Ios 尝试通过帐户和SLRequest访问Facebook时,令牌无效

Ios 尝试通过帐户和SLRequest访问Facebook时,令牌无效,ios,objective-c,facebook,acaccount,slrequest,Ios,Objective C,Facebook,Acaccount,Slrequest,我试图从用户的facebook收件箱中读取消息,但遇到了一个拒绝访问的错误。这是我的代码: ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *fbAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; NSDictionary *opti

我试图从用户的facebook收件箱中读取消息,但遇到了一个拒绝访问的错误。这是我的代码:

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *fbAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSDictionary *options = @{
                              ACFacebookAppIdKey : FacebookAppKey,
                              ACFacebookPermissionsKey : FacebookPermissionsArray
                              };
    [accountStore requestAccessToAccountsWithType:fbAccountType options:options completion:^(BOOL granted, NSError *error)
     {
         if (error || !granted) {
             return;
         }
         NSArray *accounts = [accountStore accountsWithAccountType:fbAccountType];

         if (accounts.count == 0) {
             return;
         }

         ACAccount *facebookAccount = [accounts lastObject];

         NSURL *inboxURL = [NSURL URLWithString:@"https://graph.facebook.com/me/inbox"];
         NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];

         SLRequest *facebookInfoRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                             requestMethod:SLRequestMethodGET
                                                                       URL:inboxURL
                                                                parameters:parameters];
         [facebookInfoRequest setAccount:facebookAccount];
         [facebookInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

             NSLog(@"response data: %i, url response: %@, error: %@", responseData.length, urlResponse, error);
         }];
     }];
对此的URL响应为:

<NSHTTPURLResponse: 0xcb5fa10> { URL: https://graph.facebook.com/me/inbox?access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX } { status code: 400, headers {
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "no-store";
    Connection = "keep-alive";
    "Content-Length" = 194;
    "Content-Type" = "application/json; charset=UTF-8";
    Date = "Tue, 18 Feb 2014 15:29:36 GMT";
    Expires = "Sat, 01 Jan 2000 00:00:00 GMT";
    Pragma = "no-cache";
    "Www-Authenticate" = "OAuth \"Facebook Platform\" \"invalid_token\" \"Error validating access token: Session has expired on Feb 13, 2014 6:17am. The current time is Feb 18, 2014 7:29am.\"";
    "X-FB-Debug" = "XXXXXXXXXXXXXXXX/Y+K0w=";
    "X-FB-Rev" = XXXXXXXX;
} }
{URL:https://graph.facebook.com/me/inbox?access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX }{状态代码:400,标题{
“访问控制允许来源”=“*”;
“缓存控制”=“无存储”;
连接=“保持活动”;
“内容长度”=194;
“内容类型”=“应用程序/json;字符集=UTF-8”;
日期=“2014年2月18日星期二15:29:36 GMT”;
Expires=“2000年1月1日星期六00:00:00 GMT”;
Pragma=“无缓存”;
“Www Authenticate”=“OAuth\”Facebook平台\“\”验证访问令牌时出错:会话已于2014年2月13日上午6:17过期。当前时间为2014年2月18日上午7:29。”;
“X-FB-Debug”=“XXXXXXXXXXXXXX/Y+K0w=”;
“X-FB-Rev”=XXXXXXXX;
} }

我不确定为什么会发生这个问题。我可能做错了什么?

设备上的Facebook帐户与服务器和SDK缓存不同步。 要强制更新,只需调用
ACAccountStore的
方法
续订帐户的凭证

- (void)refreshFacebookTokenStatus
{
    ACAccountStore *accountStore;
    ACAccountType *accountTypeFB;

    if ((accountStore = [[ACAccountStore alloc] init]) &&
        (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]))
    {
        NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];

        id account;

        if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0]))
        {
            [accountStore renewCredentialsForAccount:account 
                                          completion:^(ACAccountCredentialRenewResult renewResult, NSError *error)
            {
                if (error)
                {
                    NSLog(@"%@", error.localizedDescription);
                }
            }];
        }
    }
}
最简单的方法是在每次应用启动时调用它,但这可能没有效率。因此,最好在会话状态发生更改时调用它


如果您试图使用非应用程序开发人员Facebook用户登录,请确保您的Facebook应用程序设置未启用“沙盒”(Sandbox)选项。

设备上的Facebook帐户已与服务器和SDK缓存不同步。 要强制更新,只需调用
ACAccountStore的
方法
续订帐户的凭证

- (void)refreshFacebookTokenStatus
{
    ACAccountStore *accountStore;
    ACAccountType *accountTypeFB;

    if ((accountStore = [[ACAccountStore alloc] init]) &&
        (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]))
    {
        NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];

        id account;

        if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0]))
        {
            [accountStore renewCredentialsForAccount:account 
                                          completion:^(ACAccountCredentialRenewResult renewResult, NSError *error)
            {
                if (error)
                {
                    NSLog(@"%@", error.localizedDescription);
                }
            }];
        }
    }
}
最简单的方法是在每次应用启动时调用它,但这可能没有效率。因此,最好在会话状态发生更改时调用它


如果您试图使用非应用程序开发人员Facebook用户登录,请确保您的Facebook应用程序设置未启用“沙盒”(Sandbox)选项。

设备上的Facebook帐户已与服务器和SDK缓存不同步。 要强制更新,只需调用
ACAccountStore的
方法
续订帐户的凭证

- (void)refreshFacebookTokenStatus
{
    ACAccountStore *accountStore;
    ACAccountType *accountTypeFB;

    if ((accountStore = [[ACAccountStore alloc] init]) &&
        (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]))
    {
        NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];

        id account;

        if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0]))
        {
            [accountStore renewCredentialsForAccount:account 
                                          completion:^(ACAccountCredentialRenewResult renewResult, NSError *error)
            {
                if (error)
                {
                    NSLog(@"%@", error.localizedDescription);
                }
            }];
        }
    }
}
最简单的方法是在每次应用启动时调用它,但这可能没有效率。因此,最好在会话状态发生更改时调用它


如果您试图使用非应用程序开发人员Facebook用户登录,请确保您的Facebook应用程序设置未启用“沙盒”(Sandbox)选项。

设备上的Facebook帐户已与服务器和SDK缓存不同步。 要强制更新,只需调用
ACAccountStore的
方法
续订帐户的凭证

- (void)refreshFacebookTokenStatus
{
    ACAccountStore *accountStore;
    ACAccountType *accountTypeFB;

    if ((accountStore = [[ACAccountStore alloc] init]) &&
        (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]))
    {
        NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];

        id account;

        if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0]))
        {
            [accountStore renewCredentialsForAccount:account 
                                          completion:^(ACAccountCredentialRenewResult renewResult, NSError *error)
            {
                if (error)
                {
                    NSLog(@"%@", error.localizedDescription);
                }
            }];
        }
    }
}
最简单的方法是在每次应用启动时调用它,但这可能没有效率。因此,最好在会话状态发生更改时调用它

如果您试图使用非应用程序开发人员Facebook用户登录,请确保您的Facebook应用程序设置未启用
沙盒
选项