ACAccountStore Facebook错误

ACAccountStore Facebook错误,facebook,ios6,Facebook,Ios6,我有一个应用程序启用了Facebookuser\u photos权限。问题是,如果我去Facebook删除应用程序,iOS不会注意到这一点ACAccountStore说我有权限,所以requestAccess…返回“已授予”,但只要我尝试SLRequest,我就会收到一个类似验证访问令牌错误的错误:用户XXXXX没有授权应用程序YYYY,并且该应用程序不会在Facebook中重新出现 解决方法是在设备上转到设置->Facebook,然后关闭和重新打开我的应用程序的权限。下次我尝试requestA

我有一个应用程序启用了Facebook
user\u photos
权限。问题是,如果我去Facebook删除应用程序,iOS不会注意到这一点
ACAccountStore
说我有权限,所以
requestAccess…
返回“已授予”,但只要我尝试
SLRequest
,我就会收到一个类似
验证访问令牌错误的错误:用户XXXXX没有授权应用程序YYYY
,并且该应用程序不会在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删除应用程序后,我总是会收到最后一个错误(“错误加载请求:”),没有其他错误。在设备设置中切换应用程序的权限后,我获得了成功。

根据苹果公司的说法,这符合预期(BS!)。实际上,你必须先调用
renewCredentialsForAccount
使
ACAccountStore
与Facebook同步。在这种情况下,结果是
accountcredentialrenewresultjected
。然后,您可以再次调用
ACAccountStore RequestAccessToAccountSoftType
,最终将提示用户再次允许您的应用。

刚刚向Apple提交了一个错误…感谢您提及
续订Account的凭证
!您刚刚为我解决了一个我被难倒了几个小时的错误。我仍然觉得奇怪,它将返回acAccountCredentialRenewalResultRejected,但下次您检查AccountStore时,该帐户将为零。