Posts tagged with facebook-graph-api

I create a mobile app who show local crickets score card by programming in react native expo cli. https://play.google.com/store/apps/details?id=com.rafiullahkh.lcsa Now i want to update the app and want to integrate a score card in facebook/youtube live stream. If possible then gave me some hints.

I search a lot but does not find any documentation.

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)