Posts under category facebook-graph-api

I'm developing SDK for Facebook(meta) and use FBSDKGraphRequest to get some data. As the demand of access-token, I want to test the case that access-token has been invalid(mostly out of time), so I generate a short term token from fb's graph developer and wait for 2 hours until it invalid. Then I build an out-of-date token and FBSDKGraphRequest. Use FBSDKGraphRequest but nothing back(no result, no error).

I generate a short term token from fb's graph developer and wait for 2 hours until it invalid.

Use these code :

FBSDKAccessToken *access_token = [[FBSDKAccessToken alloc] initWithTokenString: @"xxxxxx"(tokenString from graph developer)                                                                        permissions:@[@"public_profile",@"email", @"user_friends"]                                                                declinedPermissions:nil                                                                 expiredPermissions:nil                                                                              appID:@"xxxxxx" (my appid)                                                                             userID:@"xxxxxx"(myuserid)                                                                     expirationDate:[NSDate dateWithTimeIntervalSince1970:1717041600]                                                                        refreshDate:[NSDate dateWithTimeIntervalSince1970:1717041500]                                                           dataAccessExpirationDate:nil];     [FBSDKAccessToken setCurrentAccessToken:access_token]; 

I generate a FBSDKAccessToken which generated by out-date tokenString and test in these code :

            FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]                                           initWithGraphPath:@"/me"                                           parameters:@{ @"fields": @"picture",}                                           HTTPMethod:@"GET"];             [request startWithCompletion:^(id<FBSDKGraphRequestConnecting>  _Nullable connection, id  _Nullable result, NSError * _Nullable error) {                 NSLog(@"request back!");                 NSLog(@"fb has error:%@", error.description);                 //get picture url             }]; 

When the token is valid(not out of date), it works and has log. But when it is invalid(out of date) , there is no log(no result no error, even no "request back!".

After long time debug and searching answer on Google, I don't find similar reason. But I find FBSDKAccessToken have a func "refreshCurrentAccessTokenWithCompletion" can also get the status of the token. So I used this to judge the token's status before FBSDKGraphRequest. But something magical happened. After I add refreshCurrentAccessTokenWithCompletion, FBSDKGraphRequest works too. It shows log "request back!".

This might be a way to solve this problem. But I think there must be a method to solve this better and some root cause.

I am running this command on my terminal :

C:\Ad-Library-API-Script-Repository-main\python> py fb_ads_library_api_cli.py -t (token) -f "id,page_id,page_name,ad_creative_bodies,spend,demographic_distribution,bylines,ad_delivery_start_time" -c "CA" -s "climate" --after-date "2024-05-01" save_to_csv file.csv 

And I get the following error :

Traceback (most recent call last): File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 147, in main() File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 134, in main save_to_csv( File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_operators.py", line 96, in save_to_csv with open(output_file, "w") as csvfile: ^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied. 

Does anyone have a solution ? i'm not sure I understand how the Permission system works in the Graph Api.

I have tried adding "encoding="utf-8" in the fb_ads_library_api_operators file to fix the encoding issue, but it didn't work (i am able to get one dataset then i get the same error all over again)

I am trying to use the Graph API to post a link (URL) to a Facebook page, using PHP and the cURL library. I am able to request a scrape with no issues. But when I try to post my URL to the page, I get the error:

(#100) Specifying multiple ids with a post method is not supported 

I believe that I have the correct scopes to post to my page, per the page Access Token:

email public_profile pages_show_list pages_read_engagement pages_manage_posts 

And it's the token for the page I am trying to post to. The URL that I'm pushing through cURL is (URL and MESSAGE are url-encoded):

$request_url =        https://graph.facebook.com/<PAGE-ID>/?id=<URL-TO-POST>&message=MESSAGE&access_token=<PAGE-TOKEN>; 

And I'm using pretty simple curl commands:

$handle = curl_init(); $curl_options = [                     CURLOPT_URL            => $request_url,                      CURLOPT_RETURNTRANSFER => true,                      CURLOPT_VERBOSE        => false,                      CURLOPT_POST           => true,                 ]; } curl_setopt_array($handle, $curl_options); $raw_data = curl_exec($handle); curl_close($handle); 

But the results I get from this call:

[error] => stdClass Object  (     [message] => (#100) Specifying multiple ids with a post method is not supported     [type] => OAuthException     [code] => 100     [fbtrace_id] => Av1ZYcuRG0hNE2KZUl94eEv  ) 

Am I using the correct URL to post? Are there missing arguments?