Facebook-ios集成(社交框架)无效权限



我正在开发两个不同的iOS应用程序:

  • 两人都与Facebook共享内容
  • 它们都与iOS 6/7兼容
  • 他们都有社会框架
  • 在这两个问题上,我在与Facebook共享时都遇到了问题

所以我做错了什么,尽管我试着关注各种各样的帖子,文档,等等

我特别遵循了这个帖子iOS 6 Facebook的发布程序,最后以";remote_app_id与存储的id不匹配";错误,它有一个很好的答案。

我想我已经在Facebook开发者中创建了我的应用程序,因为我遇到了问题(错误的iPhone ID和错误7(,在帖子之后,我提到了这些问题。

当用户点击脸书上的分享时,我会这样做:

- (void) loginWithFacebookWithReadPermissionsWithDelegate:(id<IfcRRSSDelegate>)_delegate
{
    self.delegateFB = _delegate;
    ACAccountStore *account = [[ACAccountStore alloc]init];
    ACAccountType *accountType = [cuenta accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSString *facebookKey = MY_FACEBOOK_KEY;
    NSMutableArray *permimssions = [[NSMutableArray alloc] init];
    [permimssions addObject:@"email"];
    self.fbPermission = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
                            facebookKey, ACFacebookAppIdKey,
                            ACFacebookAudienceFriends, ACFacebookAudienceKey,
                            permimssions, ACFacebookPermissionsKey, 
                            nil];
    [account requestAccessToAccountsWithType:accountType options:self.fbPermission completion:
     ^(BOOL granted, NSError *error) {
         if(granted)
         {
             NSArray *accounts = [account accountsWithAccountType: accountType];
             ACAccount *_facebookAccount = [accounts lastObject];
             self.accountFB = _facebookAccount;
             ACAccountCredential *credentials = [self.accountFB credential];
             self.tokenFB = [credentials oauthToken];
         }
         else
         {
            // Show error 
         }
     }];
}

如果这次登录进展顺利(事实上总是进展顺利(,我称之为:

- (void) loginWithFacebookWithWritePermissionsWithDelegate:(id<IfcRRSSDelegate>)_delegate
{
    self.delegateFB = _delegate;
    ACAccountStore *account = [[ACAccountStore alloc]init];
    ACAccountType *accountType = [cuenta accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSString *facebookKey = MY_FACEBOOK_KEY;
    NSMutableArray *permimssions = [[NSMutableArray alloc] init];
    [permimssions addObject:@"publish_stream"];
    [permimssions addObject:@"publish_actions"];
    self.fbPermission = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
                            facebookKey, ACFacebookAppIdKey,
                            ACFacebookAudienceFriends, ACFacebookAudienceKey,
                            permimssions, ACFacebookPermissionsKey, 
                            nil];
    [account requestAccessToAccountsWithType:accountType options:self.fbPermission completion:
     ^(BOOL granted, NSError *error) {
         NSLog(@">>>>ERROR: %@", error);
         if(granted)
         {
             NSArray *accounts = [account accountsWithAccountType: accountType];
             ACAccount *_facebookAccount = [accounts lastObject];
             self.accountFB = _facebookAccount;
             ACAccountCredential *credentials = [self.accountFB credential];
             self.tokenFB = [credentials oauthToken];
         }
         else
         {
            // Show error 
         }
     }];
}

第二次登录失败,我得到这个错误:

错误:错误域=com.apple.accounts代码=7"Facebook服务器无法完成此访问请求:无效权限:publish_stream"用户信息=0xc18d700{NSLocalizedDescription=Facebook服务器无法满足此访问请求

无效权限:publish_stream???我几乎找不到关于这个错误的信息。

我试图评论这个权限,但只有publish_action,但当我试图发布时,我得到了这个新错误:

{
    code = 200;
    message = "(#200) The user hasn't authorized the application to perform this action";
    type = OAuthException;
}

如果第二次登录顺利,我会调用此代码发布(但由于第二次登陆失败,所以从未调用(:

- (void) postWithFacebookWithMessage:(NSString *)msg
{
    if(self.accountFB)
    {
        NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
        [parameters setObject: self.accountFB.credential.oauthToken forKey:@"access_token"];
        [parameters setObject:msg forKey:@"message"];
        NSURL *requestUR = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
        SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                requestMethod:SLRequestMethodPOST
                                                          URL:requestURL
                                                   parameters:parameters];
        request.account = self.accountFB;
        [request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
            if(!error)
            {
                NSDictionary *list = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
                if([list objectForKey:@"error"] != nil)
                {
                    // Try to attempt Renew Credentials
                }
                else
                {
                    // Everything works
                }
                dispatch_async(dispatch_get_main_queue(),^{});
            }
            else
            {
                    // Try to attempt Renew Credentials
            }
        }];
    }
}

如果这很重要的话,我已经在我的facebook页面、我的活动、应用程序、这个应用程序中查看了,它说"这个应用程序可以以你的名义发布:只有你"。

知道发生了什么吗?

谨致问候!

编辑:对不起,我在解释错误时犯了一个重要错误,所以我编辑了帖子:失败的facebook呼叫是第二次登录,而不是帖子。

试试我在应用程序中使用的代码:

__block ACAccount * facebookAccount;
        ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    NSDictionary *emailReadPermisson = @{
                                         ACFacebookAppIdKey : @"0123456789",
                                         ACFacebookPermissionsKey : @[@"email"],
                                         ACFacebookAudienceKey : ACFacebookAudienceEveryone,
                                         };
    NSDictionary *publishWritePermisson = @{
                                            ACFacebookAppIdKey : @"0123456789",
                                            ACFacebookPermissionsKey : @[@"publish_actions"],
                                            ACFacebookAudienceKey : ACFacebookAudienceEveryone
                                            };
    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    //Request for Read permission
    [accountStore requestAccessToAccountsWithType:facebookAccountType options:emailReadPermisson completion:^(BOOL granted, NSError *error) {
        if (granted) {
            NSLog(@"Granted for read");
            //Request for write permission
            [accountStore requestAccessToAccountsWithType:facebookAccountType options:publishWritePermisson completion:^(BOOL granted, NSError *error) {
                if (granted) {
                    NSLog(@"Granded for post");
                    NSArray *accounts = [accountStore
                                         accountsWithAccountType:facebookAccountType];
                    facebookAccount = [accounts lastObject];
                    NSLog(@"Successfull access for account: %@", facebookAccount.username);
                    /* Do any things here */
                }
                else
                {
                    NSLog(@"Access to Facebook is not granted");
                    // Fail gracefully...
                    NSLog(@"%@",error.description);
                }
            }];
        }else{
             /* Error */
        }
    }];

此样本是在后发现的

如果您的帐户处于"未授予"状态,请检查您的应用程序是否未在Settings->Facebook中被阻止。如果是-请用户从设置中授予访问权限。

相关内容

最新更新