iOS 6 Facebook 发帖程序以“remote_app_id 与存储的 id 不匹配"告终.错误 [英] iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" error

查看:26
本文介绍了iOS 6 Facebook 发帖程序以“remote_app_id 与存储的 id 不匹配"告终.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行一个简单的发布程序:

- (IBAction)directPostClick:(id)sender {self.statusLabel.text = @"等待授权...";如果(self.accountStore == nil){self.accountStore = [[ACAccountStore alloc] init];}ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];NSArray * permissions = @[@"publish_stream", @"user_checkins", @"publish_checkins", @"user_likes", @"user_videos"];NSDictionary * dict = @{ACFacebookAppIdKey : @"My app id here", ACFacebookPermissionsKey : 权限, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL 授予,NSError *error) {__block NSString * statusText = nil;如果(授予){statusText = @"已登录";NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];self.facebookAccount = [accounts lastObject];NSLog(@"账号是:%@", self.facebookAccount);self.statusLabel.text = statusText;[self postToFeed];}别的 {self.statusLabel.text = @"登录失败";NSLog(@"错误是:%@", 错误);}}];}

问题是,当我点击 alertView 的 OK 按钮时(不允许也不起作用),什么也没有发生! - 这种行为现在改变了我认为这是同样的问题.大家怎么看?附言我在 MAC mini、OS X 10.8.1 和最新的 xcode 4.5 (4G182) 上运行,并使用 iPhone 6.0 模拟器.

添加:根据 Bjorn 的请求,添加了 postToFeed 方法,尽管它从未被调用过:

- (void)postToFeed {NSDictionary * parameters = @{@"message" : @"Hello world!"};NSURL * feedUrl = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedUrl parameters:parameters];request.account = self.facebookAccount;[请求 performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {dispatch_async(dispatch_get_main_queue(),^{self.statusLabel.text = @"已发布!";});}];}

解决方案

在使用 Accounts Framework 和 Facebook 集成时,我也遇到了一些困难.以下是我学到的知识以及我如何让它发挥作用.

1.确保您已在 Facebook 上正确设置您的应用
您需要设置您的应用如何与 Facebook 集成到iOS 原生应用,并在指定字段中输入您的应用的 Bundle ID.(请注意捆绑 ID 区分大小写)您现在可以将 iTunes ID 设置为 0.启用Facebook 登录并将高级设置选项卡中的应用类型设置为原生/桌面.
还将客户端中的应用机密设置为.

如果这些选项中的一个或多个设置不正确,您很可能会收到错误Facebook 服务器无法满足此访问请求:remote_app_id 与存储的 ID 不匹配.

(您还必须确保沙箱已禁用.)

2.首次安装 Facebook 应用
首次通过 iOS(以及 Mac OS X)上的原生 Facebook 集成安装应用程序时,您必须仅请求基本读取权限!emailuser_birthdayuser_location 在这里是不允许的.使用 user_about_me(根据 Facebook 文档也是基本读取权限)不起作用.如果您之前使用过 Facebook JavaScript SDK 或 Facebook PHP SDK,这会非常令人困惑,因为它默认要求基本权限,而您无需执行任何操作.Facebook 还更新了他们的文档,其中包含关于 如何使用新的分步指南iOS 6 上的 Facebook SDK.

3.请求额外权限
重要的是要知道,您可能不会同时请求读取和写入权限.这也是经验丰富的 Facebook SDK 开发人员可能会感到困惑的事情.请求read_stream 权限和publish_stream 权限将使请求失败,导致错误应用可能不会同时请求读写权限.

因为 Facebook 在权限参考,必须自己确定写权限.它们通常以 manage_*publish_*create_* 为前缀或以 *_management 为后缀.

Facebook 也不建议在获得基本权限后立即请求其他权限.文档 说您现在需要分别请求读取和发布权限(并按此顺序).最有可能的是,您将在应用启动和用户首次登录时请求个性化的读取权限.稍后,如果合适,您的应用可以在需要时请求发布权限将数据发布到 Facebook.[...] 分别请求这两种类型也大大提高了用户授予发布权限的机会,因为您的应用程序只会在需要它们的时候寻找它们,最有可能的是当用户有更强烈的意图.".

4.示例代码
以下示例代码应该适用于 iOS 和 Mac OS X:

ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];//首先,我们只要求基本的读权限NSArray * 权限 = @[@"email"];NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"My app id here", ACFacebookAppIdKey, 权限, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL 授予,NSError *error) {如果(授予&&错误== nil){/*** 用户授予我们基本读取权限.* 现在我们可以请求更多权限**/NSArray *readPermissions = @[@"read_stream", @"read_friendlists"];[dict setObject:readPermissions forKey: ACFacebookPermissionsKey];[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL 授予,NSError *error) {如果(授予&&错误== nil){/*** 我们现在应该有一些读取权限* 现在我们可能会要求写权限或* 做别的事情.**/} 别的 {NSLog(@"错误是:%@",[错误描述]);}}];} 别的 {NSLog(@"错误是:%@",[错误描述]);}}];

I'm trying to perform a simple posting procedure:

- (IBAction)directPostClick:(id)sender {
    self.statusLabel.text = @"Waiting for authorization...";
    if (self.accountStore == nil) {
        self.accountStore = [[ACAccountStore alloc] init];
    }   
    ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSArray * permissions = @[@"publish_stream", @"user_checkins", @"publish_checkins", @"user_likes", @"user_videos"];
    NSDictionary * dict = @{ACFacebookAppIdKey : @"My app id here", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
    [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
        __block NSString * statusText = nil;
        if (granted) {
            statusText = @"Logged in";
            NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
            self.facebookAccount = [accounts lastObject];
            NSLog(@"account is: %@", self.facebookAccount);
            self.statusLabel.text = statusText;
            [self postToFeed];
        }
        else {
            self.statusLabel.text = @"Login failed";
            NSLog(@"error is: %@", error);
        }
    }];
} 

EDITED: The problem is that when I click on alertView's OK button (don't allow doesn't work either) nothing happens! - This behavoir now changed with this iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" So instead of just "nothing happens" I've got an error "The Facebook server could not fulfill this access request: remote_app_id does not match stored id"

So , it seems that alert view's click handler doing nothing, my completionHandler is never called. I do have the similar problem already: iOS 6 Social integration - go to settings issue And I think that it is the same problem here. What do you guys think about it? P.S. I'm running on MAC mini, OS X 10.8.1 with latest xcode 4.5 (4G182) and using iPhone 6.0 simulator.

ADDED: By the Bjorn's request adding the postToFeed method although it is never called:

- (void)postToFeed {
    NSDictionary * parameters = @{@"message" : @"Hello world!"};
    NSURL * feedUrl = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
    SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedUrl parameters:parameters];
    request.account = self.facebookAccount;
    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.statusLabel.text = @"Posted!";
        });
    }];
}

解决方案

I also experienced some difficulties when working with the Accounts Framework and the Facebook integration. Here is what I've learned and how I got it working.

1. Make sure you've setup your App on Facebook correctly
You need to set how your App integrates with Facebook to Native iOS App and enter the Bundle ID of your App into the designated field. (Edit: Note that bundle IDs are case sensitive) You can set the iTunes ID to 0 for now. Enable Facebook Login and set the App Type in the advanced settings tab to Native/Desktop.
Also set App Secret in Client to No.

If one or more of these options are not set correctly it's very likely you get the error The Facebook server could not fulfill this access request: remote_app_id does not match stored id.

(Edit: You also have to ensure the sandbox is disabled.)

2. Installing the Facebook App for the first time
When first installing an App via the native Facebook integration on iOS (and Mac OS X too), you must ask for a basic read permission only! Nothing else as email, user_birthday and user_location is allowed here. Using user_about_me, which is also a basic read permission according to the Facebook documentation, does not work. This is pretty confusing if you previously worked with the Facebook JavaScript SDK or the Facebook PHP SDK, because it asks for the basic permissions by default without you having to do something. Facebook also updated their documentation with a short step-by-step guide on how to use the new Facebook SDK on iOS 6.

3. Requesting additional permissions
It's important to know, that you may not ask for read and write permissions at the same time. That's also something experienced Facebook SDK developers may find confusing. Requesting the read_stream permission along with the publish_stream permission will make the request fail, resulting in the error An app may not aks for read and write permissions at the same time.

As Facebook does not really distinguish between read/write permissions in the Permission Reference, you must identify write permissions by yourself. They're usually prefixed with manage_*, publish_*, create_* or suffixed by *_management.

Facebook does also not recommend to ask for additional permissions immediately after getting basic permissions. The documentation says "You are now required to request read and publish permission separately (and in that order). Most likely, you will request the read permissions for personalization when the app starts and the user first logs in. Later, if appropriate, your app can request publish permissions when it intends to post data to Facebook. [...] Asking for the two types separately also greatly improves the chances that users will grant the publish permissions, since your app will only seek them at the time it needs them, most likely when the user has a stronger intent.".

4. Sample Code
The following sample code should work on iOS and Mac OS X:

ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// At first, we only ask for the basic read permission
NSArray * permissions = @[@"email"];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"My app id here", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];

[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
    if (granted && error == nil) {
        /** 
        * The user granted us the basic read permission.
        * Now we can ask for more permissions
        **/
        NSArray *readPermissions = @[@"read_stream", @"read_friendlists"];
        [dict setObject:readPermissions forKey: ACFacebookPermissionsKey];

        [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
            if(granted && error == nil) {
                /**
                * We now should have some read permission
                * Now we may ask for write permissions or
                    * do something else.
                **/
            } else {
                NSLog(@"error is: %@",[error description]);
            }
        }];
    } else {
        NSLog(@"error is: %@",[error description]);
    }
}];

这篇关于iOS 6 Facebook 发帖程序以“remote_app_id 与存储的 id 不匹配"告终.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆