无法正确处理会话

时间:2012-07-19 07:29:58

标签: iphone facebook access-token

我正在使用Xcode 4.3.1

我使用以下代码获取Facebook访问令牌。

在Appdelegate中:

facebook=[[Facebook alloc]initWithAppId:appid andDelegate:first];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] 
    && [defaults objectForKey:@"FBExpirationDateKey"]) 
{
   facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
   facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
   accessToken=facebook.accessToken;
   date=facebook.expirationDate;
}
 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [ self.facebook handleOpenURL:url];
}

Facebook SSO(登录)   在viewController中:

- (IBAction为)LoginClick:(ID)发送方     {

    accesstoken=xapp.accessToken;
    date=xapp.date;
    [self fbDidExtendToken:xapp.accessToken expiresAt:xapp.date];  //For extending tokens
    NSLog(@"accesstoken:%@",accesstoken);
    if (![xapp.facebook isSessionValid]) 
    {
        [xapp.facebook authorize:permissions];
    }
    else 
    { 
        [xapp.facebook authorize: nil];

    }
}

这里我无法正确处理会话。我的要求是第一次用户必须登录,他应该授权应用程序。一旦他完成应用程序不应该要求授权。现在它要求授权每个我一直在运行应用程序。我怎么能解决这个问题.....

2 个答案:

答案 0 :(得分:0)

使用最新的FBGraph API ....查看此链接How to share or post by mail, twitter and facebook from the current application?以获取进一步的查询。这篇文章包括FB,Twitter和EMail的所有最新技术。

答案 1 :(得分:0)

登录后是否将令牌保存为用户默认值?

 // this is a delegate method of FBSessionDelegate, called after user successfully login
- (void)fbDidLogin 
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[xapp.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[xapp.facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
}