【问题标题】:Facebook - ios integration (Social Framework) Invalid permissionFacebook - ios 集成(社交框架)权限无效
【发布时间】:2014-06-05 17:22:13
【问题描述】:

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

  • 他们都与 Facebook 共享内容。
  • 它们都使用 iOS 6/7。
  • 它们都具有社交框架
  • 我在与 Facebook 共享时遇到了问题。

因此,尽管我尝试关注所有类型的帖子、文档等,但我做错了什么。

我专门关注了iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" error这个帖子,答案很好。

我认为我已经在 Facebook Developers 中创建了我的应用程序,因为我遇到了问题(错误的 iPhone ID 和错误 7),并且在帖子之后我提到了这些问题消失了。

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

- (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 
         }
     }];
}

第二次登录失败,我收到此错误:

ERROR: Error Domain=com.apple.accounts Code=7 "Facebook 服务器无法完成此访问请求:无效权限:publish_stream" UserInfo=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 调用是第二次登录,而不是帖子。

【问题讨论】:

    标签: ios facebook social-framework


    【解决方案1】:

    试试我在我的应用中使用的这段代码:

    __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 */
            }
        }];
    

    这个样本是在this post找到的

    如果您的帐户处于“未授予”状态 - 请检查您的应用是否未在 Settings-&gt;Facebook 中被阻止。如果是 - 要求用户从设置中授予访问权限。

    【讨论】:

    • 完美!那行得通!非常感谢你!我认为问题在于如何请求权限。
    • 简单地将 publish_stream 替换为 publish_actions 对我有用,希望此评论可以帮助其他人完成 Ray Wenderlich iSocial facebook 集成章节。
    • @vladislav,它在 iOS 7 中工作,但我试图在 iOS8 中发布它进入“NSLog(@"Granted for post");"这部分,但是当要分享帖子时,它会给出错误:“请求状态为 403”,这是怎么回事?
    • 阅读 facebook 关于权限的指南。 不需要审查的权限公开个人资料(默认)权限。应用好友。电子邮件权限 publish_actions: -- 您的应用无需请求 publish_actions 权限即可使用 Feed 对话框、请求对话框或发送对话框 -- 您的应用无需请求 publish_actions 权限为了使用提要对话框、请求对话框或发送对话框,请检查 [link]developers.facebook.com/docs/facebook-login/permissions/…
    • 我仍然得到“(#200)用户尚未授权应用程序执行此操作”..请帮助
    猜你喜欢
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    相关资源
    最近更新 更多