【问题标题】:ACAccountStore Facebook errorACAccountStore Facebook 错误
【发布时间】:2012-09-27 23:26:54
【问题描述】:

我有一个启用了 Facebook user_photos 权限的应用。问题是如果我去 Facebook 并删除应用程序,iOS 不会注意到这一点。 ACAccountStore 表示我有权限,所以 requestAccess... 返回“已授予”,但当我尝试 SLRequest 时,我会收到类似 Error validating access token: User XXXXX has not authorized application YYYYY 的错误,并且该应用不会重新出现在 Facebook 中。

解决方法是转到设备上的“设置”->“Facebook”,然后关闭并重新打开我的应用程序的权限。下次我尝试requestAccess 时,系统会要求我再次确认访问权限,然后在 Facebook 中重新安装该应用程序,一切正常。

ACAccountStore *accountStore = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

[accountStore requestAccessToAccountsWithType:accountType
                                      options:@{ACFacebookAppIdKey:       kFacebookAppID,
                                                ACFacebookPermissionsKey: @[@"user_photos"]}
                                   completion:^(BOOL granted, NSError *error)
{
   if( error ) {
      NSLog( @"account permission error %@", error );
   }
   else if( granted ) {
      NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/albums"];
      SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                              requestMethod:SLRequestMethodGET
                                                        URL:requestURL
                                                 parameters:[NSMutableDictionary dictionary]];
      NSArray *accounts = [accountStore accountsWithAccountType:accountType];
      if( [accounts count] > 0 ) {
         request.account = accounts[0];
         [request performRequestWithHandler:^ (NSData *responseData, NSHTTPURLResponse *response, NSError *error)
         {
            if( error ) {
               NSLog( @"error accessing Facebook account: %@", error );
            }
            else {
               NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
               if( data[@"error"] != nil ) {
                  NSLog( @"error loading request: %@", data[@"error"] );
               }
               else {
                  NSLog( @"success! %@", data );
               }
            }
         }];
      }
      else {
         NSLog( @"error: no Facebook accounts" );
      }
   }
}];

就我而言,从 Facebook 删除应用程序后,我总是收到最终错误(“错误加载请求:”),没有其他错误。在设备的设置中切换应用程序的权限后,我就成功了。

【问题讨论】:

  • 刚刚向 Apple 提交了一个错误...

标签: facebook ios6


【解决方案1】:

根据 Apple 的说法,这是按预期工作的(BS!)。在实践中,您必须先调用renewCredentialsForAccount 才能使ACAccountStore 与Facebook 同步。在这种情况下,结果是ACAccountCredentialRenewResultRejected。然后你可以再次调用ACAccountStore requestAccessToAccountsOfType,最终会提示用户再次允许你的应用。

【讨论】:

  • 感谢您提及renewCredentialsForAccount!你刚刚为我解决了一个困扰我好几个小时的错误。
  • 我仍然觉得奇怪的是它会返回一个 ACAccountCredentialRenewResultRejected 但下次您检查 AccountStore 时,Account 将为 nil。
猜你喜欢
  • 2012-07-11
  • 2013-05-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
  • 1970-01-01
相关资源
最近更新 更多