1

Once the User's Facebook Access Token is Invalidated for any reason (either deleting the app from the Facebook website or deleting the app's access from the Facebook settings), I Can't manage to Get a NEW TOKEN, no matter what I Do!

So Far, I've tried two methods: (sharedFaceBookManager is a Singleton that Manages Facebook)

1) [sharedFaceBookManager.facebook extendAccessToken];

This Works for the First time the "Invalidation" happens, the App will open FB's App and Prompt the User for whatever is Required and return to the App Safe and sound... The SECOND time the Access token is Invalid, extendAccessToken will just Hang there and the user will no longer be able to login through Facebook. Not a good Solution.

2) Attempting to Delete Cookies, Disconnect form Facebook, and Re-Connect!

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {

    if([[cookie domain] isEqualToString:@"facebook"]) {

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}

// Reconnecting:
NSArray *permissions = [NSArray arrayWithObjects:@"email", @"read_friendlists", @"user_photos", @"user_events", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,
   FBSessionState state, NSError *error) {
     [[EWFacebookManager sharedFaceBookManager] sessionStateChanged:session state:state error:error];
 }];

This Only returns a Call to - (void)sessionStateChanged: with:FBSessionStateOpenand the Apps Deals with this as if Login Succeeded, Result: ENDLESS LOOP (Login Success - Login Failed) NOT A GOOD SOLUTION!

I Know I Shouldn't call extendAccessToken when the Token is invalid, I Should Prompt the User to Login Again

ANYBODY? Please? We've even turned to an outsourcing company to help us deal with this and NO BREAK THROUGH!

4

2 回答 2

5

解决了!!!

因此,结论:您不能扩展无效的 Facebook 访问令牌。相反,您应该清理您的 AccessToken 并通过您的 FBSession 更新您的 Facebook 凭据。

  • 首先,我断开与 Facebook 的连接并清理我的令牌数据。
  • 然后我为 FBSession 更新我的凭证
  • 最后我尝试通过打开一个新的活动会话来重新连接。

这是我的代码(“无效的 fb 令牌”将调用“renewFacebookCredentials”,然后将执行“facebookReconnect”):

- (void)facebookReconnect
{
    NSArray *permissions = [NSArray arrayWithObjects:@"email", @"read_friendlists", @"user_photos", @"user_events", nil];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [[EWFacebookManager sharedFaceBookManager] sessionStateChanged:session state:state error:error];
     }];

}

+ (void)renewFacebookCredentials
{
    [FBSession.activeSession closeAndClearTokenInformation];
    [FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result,
                                        NSError *error)
     {
         [[EWFacebookManager sharedFaceBookManager] facebookReconnect]; 
     }];
}

我希望这可以帮助一些迷失的灵魂,并防止对新的 Facebook iOS SDK 及其“弱”文档产生更多仇恨;-)

埃尔南

于 2013-05-21T09:02:02.240 回答
0

你应该这样编码,

1)此代码将在用户登录完成后执行......(如果它位于 appdelegate 意味着,这是一个好主意)

if( SYSTEM_VERSION_LESS_THAN(@"6.0"))
        [[self facebook] extendAccessTokenIfNeeded];
    else
        if( [[FBSession activeSession] respondsToSelector:@selector(handleDidBecomeActive)])
            [FBSession.activeSession handleDidBecomeActive];

2)当你调用facebook时,你应该验证会话,否则会导致错误。代码应该:

if (![[self.appDelegate facebook] isSessionValid]) {
            NSArray *permissions = [[NSArray alloc] initWithObjects:@"offline_access", nil];
            [[self.appDelegate facebook] authorize:permissions];
            [permissions release];
        }
于 2013-05-20T13:36:28.507 回答