【问题标题】:facebook sdk ios expiration datefacebook sdk ios 到期日期
【发布时间】:2011-04-03 07:44:17
【问题描述】:

我正在尝试记录 facebook 的令牌和到期日期,因为不是每次都授权用户。但是今晚我收到了这个错误,例如:{"error":{"type":"OAuthException"。 首先让我解释一下我如何以及何时记录到期日期和令牌:

在DidLogin:

-(void)fbDidLogin{
[[NSUserDefaults standardUserDefaults]setValue:facebook.accessToken            forKey:@"fb_access_token"];
[[NSUserDefaults standardUserDefaults]setObject:facebook.expirationDate forKey:@"fb_expiration_date"];

在登录中:

facebook.accessToken    = [[NSUserDefaults standardUserDefaults] stringForKey:@"fb_access_token"];
facebook.expirationDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"fb_expiration_date"];

if (![facebook isSessionValid]) {
    NSLog(@"session not valid authorize again"); 
    [facebook authorize:_permissions delegate:self];
}   
else
{
    if([delegate respondsToSelector:@selector(didFB_login)])[delegate didFB_login];
    self.loggedin=TRUE;
}

经过NSLog我明白了这个问题:

我的有效期是

exp date:4001-01-01 00:00:00 +0000

所以为了确保我没有犯错,我修改了facebook.m:

//FBLoginDialogDelegate

/**
* Set the authToken and expirationDate after login succeed
*/
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate {
self.accessToken = token;
self.expirationDate = expirationDate;
NSLog(@"self.expirationDate:%@",self.expirationDate);
if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogin)]) {
[_sessionDelegate fbDidLogin];
}

}

然后强制进行新的授权调用,但结果仍然是:

self.expirationDate:4001-01-01 00:00:00 +0000

现在的问题是:Facebook OAuth 中是否存在错误?如何确定问题不在我的日期保存代码中?

【问题讨论】:

    标签: iphone facebook ios


    【解决方案1】:

    FB 不赞成在长期会话中使用“offline_access”。更多信息请参考https://developers.facebook.com/docs/offline-access-deprecation/。

    这里:https://developers.facebook.com/docs/mobile/ios/build/#extend_token 如果您在 iOS 中开发。

    干杯!

    【讨论】:

      【解决方案2】:

      该死的,经过一些调试后我发现 处理OpenURL 查询:access_token=accesstokenstring&expires_in=0

      为什么 OAuth 回答我 expires_in 0 ?当然日期是 4001 原因

      // We have an access token, so parse the expiration date.
      NSString *expTime = [params valueForKey:@"expires_in"];
      NSLog(@"expTime:%@",expTime);
      NSDate *expirationDate = [NSDate distantFuture];
      if (expTime != nil) {
      int expVal = [expTime intValue];
      if (expVal != 0) {
        expirationDate = [NSDate dateWithTimeIntervalSinceNow:expVal];
      

      expVal 为 0,因此到期日期为远期未来。 但是令牌已过期,当我尝试使用该令牌进行查询时,我得到了 oauth 期望。 所以?有人知道吗?

      已解决.. 如果有人想知道为什么会发生这种情况,这就是答案:由于offline_access 权限,expires_in 为 0。由于 facebook 密码更改,Burt 令牌在服务器端过期。要解决这个问题,只需添加

        - (void)request:(FBRequest *)request didFailWithError:(NSError *)error{
      
      NSLog(@"didFailWithError : %@",[error description]);
      
      NSDictionary* userinfo=[error userInfo];
      // NSLog(@"userinfo:%@",userinfo);
      NSString *type=[[userinfo valueForKey:@"error"]valueForKey:@"type"];
      // NSLog(@"type:%@",type);
      if([type isEqualToString:@"OAuthException"]){
          NSLog(@"Exception from oauth let's take new token");
      [facebook authorize:_permissions delegate:self];
      
      }
      

      【讨论】:

      • 已解决.. 如果有人想知道为什么会发生这种情况,这就是答案:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 2016-01-29
      • 2012-01-06
      • 2013-01-05
      相关资源
      最近更新 更多