Thursday, May 30, 2024
HomeiOS Developmentc - FBSDKGraphRequest do not work if entry token out of time(iOS)

c – FBSDKGraphRequest do not work if entry token out of time(iOS)


I am growing SDK for Fb(meta) and use FBSDKGraphRequest to get some information. Because the demand of access-token, I need to take a look at the case that access-token has been invalid(principally out of time), so I generate a brief time period token from fb’s graph developer and wait for two hours till it invalid. Then I construct an out-of-date token and FBSDKGraphRequest. Use FBSDKGraphRequest however nothing again(no consequence, no error).

I generate a brief time period token from fb’s graph developer and wait for two hours till 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 take a look at in these code :

            FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                          initWithGraphPath:@"/me"
                                          parameters:@{ @"fields": @"image",}
                                          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 legitimate(not old-fashioned), it really works and has log. However when it’s invalid(old-fashioned) , there is no such thing as a log(no consequence no error, even no “request again!”.

After very long time debug and looking reply on Google, I do not discover related motive. However I discover FBSDKAccessToken have a func “refreshCurrentAccessTokenWithCompletion” can even get the standing of the token. So I used this to evaluate the token’s standing earlier than FBSDKGraphRequest. However one thing magical occurred. After I add refreshCurrentAccessTokenWithCompletion, FBSDKGraphRequest works too. It reveals log “request again!”.

This is perhaps a technique to resolve this downside. However I feel there have to be a way to resolve this higher and a few root trigger.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments