Posts tagged with sdk

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.