Posts tagged with facebook-graph-api

I find the Facebook developers API documentation a bit confusing. I'm building a small app using PHP and I would like to fetch/scrape data from a page which isn't belong to me.

is it possible using the API or i will need to scrape the data manually? If it's possible, is it possible if i'm not the owner of the page as well?

I am using nodejs to make an api call to add captions to the uploaded video. The response I am getting is success but the captions are not available on the video.

The video is uploaded using {{fb_page_id}}/videos. It returns me a videoId of posted video. Once the video is posted, I am calling {{video_id}}/captions endpoints with caption_file as path to my local file of subtitles. The filename is in the correct format of filename.locale.srt.

Here's the documentation link for captions upload https://developers.facebook.com/docs/graph-api/reference/video/captions/

While using the curl, It is working fine. Here's the curl I am using curl -F 'captions_file=@\"${subtitleFilePath}\"' -F 'method=POST' 'https://graph-video.facebook.com/v19.0/1109093056874668/captions?access_token={{access_token}}&default_locale=none&locales_to_delete=[]'

Looking how to make this request using something like axios, or nodejs-request

This error arises when the Facebook SDK detects a potential security risk during the login process. The state parameter acts as a crucial security measure to prevent Cross-Site Request Forgery (CSRF) attacks. It ensures that the request to obtain a Facebook access token originates from your legitimate application and not a malicious source.

class FacebookAuthController extends Controller { protected $helpers = ['url', 'session']; // Load the URL and session helper

private $fb; // Declare Facebook object as a private property public function __construct() {     include_once APPPATH . "Libraries/vendor/autoload.php";     // Initialize Facebook SDK in the constructor     $this->fb = new Facebook([         'app_id' => '=',         'app_secret' => '',         'default_graph_version' => 'v11.0',     ]); } public function login() {     // Use the previously initialized Facebook object from the property     $fb = $this->fb;     // Redirect to Facebook's OAuth consent screen     $helper = $fb->getRedirectLoginHelper();     $redirectURL = base_url('auth/facebook/callback');     // Generate a CSRF token and save it in session     $csrfToken = bin2hex(random_bytes(32)); // Generate a random token     session()->set('csrf_token', $csrfToken);     $permissions = ['email']; // Specify the permissions you need     $loginURL = $helper->getLoginUrl($redirectURL, $permissions);     // Append the CSRF token to the login URL as state parameter     $loginURL .= '&state=' . $csrfToken;     return redirect()->to($loginURL); } public function callback() {     // Use the previously initialized Facebook object from the property     $fb = $this->fb;     try {         $accessToken = $fb->getRedirectLoginHelper()->getAccessToken();         if (!$accessToken) {             throw new Exception('No access token received');         }         // Validate CSRF token         $state = $this->request->getGet('state');         $csrfToken = session()->get('csrf_token');         if ($state !== $csrfToken) {             throw new Exception('CSRF token mismatch');         }         // Implement your Facebook API logic using $accessToken and $fb         // ... (e.g., get user data, store access token, create user account)         $userData = $fb->get('/me?fields=id,name,email', $accessToken);         $facebookData = $userData->getData();         // Example usage (replace with your specific logic)         if (isset($facebookData['email'])) {             $email = $facebookData['email'];             // ... (check user existence in your database, create account if needed) ...         }         // ... (Handle successful login) ...     } catch (\Facebook\Exceptions\FacebookResponseException $e) {         // Handle Facebook API response error         echo 'Facebook API Error: ' . $e->getMessage();     } } 

}`

Facebook SDK returned an error: Cross-site request forgery validation failed. Required param "state" missing.

I received FB email saying

Your app is currently accessing Graph API v13.0 which will reach the end of its 2-year lifetime on 28 May, 2024. We estimate 7 endpoints that App calls will be impacted by this change and may stop working after the automatic upgrade push.

However, when I go to the API Upgrade Tool, it said

Your app has no changes for the methods you selected between v13.0 and v19.0

Does it mean I don't need to do anything, e.g. upgrade my FB client library?

We have an application with Facebook that has been successfully granted several permissions in the past. I know that the process of getting app permissions with meta has always been unnecessarily difficult and I expected nothing less when applying for the 'Page Public Content Access' permission.

However, this has turned out to be substantially more challenging than predicted.

Initially we tried accessing the permission from our currently 'live' application which didn't work and were quickly guided by meta support to create a test application (a copy of the parent application) and attempt to use the endpoints/permissions based on this 'development' application.

This is what we did and we added the 'pages_show_list' and 'pages_read_engagement' permissions before requesting an access token in order to test the 'pages/search' endpoint that we would be screencasting for our permissions approval.

This though is giving us the exact same results

{ "error": {     "message": "(#10) This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature or the 'Page Public Metadata Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage-pages, https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS and https://developers.facebook.com/docs/apps/review/feature#page-public-metadata-access for details.",     "type": "OAuthException",     "code": 10,     "fbtrace_id": "AICjKBRUbuIP8RrzxSfYG1C"   } } 

I feel like I've read the documentation a million times and it has not improved my understanding, nor my mood towards their application mechanism.

What are we doing wrong here?