使用Parse发布指向Facebook时间线的链接

时间:2012-10-26 09:27:32

标签: iphone objective-c ios facebook

我正在使用Parse移动平台在Facebook时间线上发布Feed。这就是他们在文档中所说的:Note that if you already have the Facebook SDK installed in your app, our version of the Facebook SDK will happily work alongside it.

看看hereThe Parse SDK includes the entire Facebook SDK. All the classes are namespaced with PF_ to avoid conflicts with existing libraries. So, for example, the main Facebook object class in our SDK is PF_Facebook.

这个使用Facebook SDK完美无缺:

- (IBAction)postFacebook:(UIButton *)sender {    
    self.postParams =
    [[NSMutableDictionary alloc] initWithObjectsAndKeys:
     @"https://developers.facebook.com/ios", @"link",
     @"https://developers.facebook.com/attachment/iossdk_logo.png", @"picture",
     @"Facebook SDK for iOS", @"name",
     @"Here we go", @"message",
     @"Build great social apps and get more installs.", @"caption",
     @"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", @"description",
     nil];

    [FBRequestConnection startWithGraphPath:@"me/feed" parameters:self.postParams HTTPMethod:@"POST"
     completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        [self showAlert:@"Link is posted" result:result error:error];
     }];
}

但是当我使用PF_FBRequestConnection时,它不起作用:

[PF_FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST"
        completionHandler:^(PF_FBRequestConnection *connection, id result, NSError *error) {
            [self showAlert:@"Link is posted" result:result error:error];
    }];

控制台中的错误:

Error: HTTP status code: 403

问题是,我可以使用Parse发布photo or Status,但不是您看到的链接。

我感谢任何帮助。

2 个答案:

答案 0 :(得分:2)

问题是我正在使用的Parse框架的版本。您也可以查看here

例如,该版本(1.1.12)不支持此版本:

[PF_FBSession.activeSession handleDidBecomeActive];

在新版本(1.1.13)中,问题得以解决。所以我可以使用这种方法:

// Convenience method to perform some action that requires the "publish_actions" permissions.
- (void) performPublishAction:(void (^)(void)) action {
    // we defer request for permission to post to the moment of post, then we check for the permission
    if ([PF_FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
        // if we don't already have the permission, then we request it now
        [PF_FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
            defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(PF_FBSession *session, NSError *error) {
                if (!error) {
                    action();
                }
            //For this example, ignore errors (such as if user cancels).
        }];
    } else {
        action();
    }
}

以这种方式使用它:

[self performPublishAction:^{
        [PF_FBRequestConnection startWithGraphPath:@"me/feed" parameters:self.postParams HTTPMethod:@"POST"
            completionHandler:^(PF_FBRequestConnection *connection, id result, NSError *error) {
                [self showAlert:@"Link is posted" result:result error:error];
        }];
    }];

答案 1 :(得分:0)

您必须检查您的应用拥有的权限。来自Facebook SDK documentation

insufficient_scope:请求需要的权限高于访问令牌提供的权限。资源服务器应该响应HTTP 403(Forbidden)状态代码,并且可以包含“scope”属性以及访问受保护资源所需的范围。