0

我正在尝试创建一个活动,但我阅读的所有教程都已过时或不再有效。

[FBRequest
 startWithGraphPath:@"me/events"
 parameters:params
 HTTPMethod:@"POST"
 completionHandler:^(FBRequestConnection *connection,
                   id result,
                     NSError *error) {
     if (error) {
         NSLog(@"Error: %@", result);
     } else {
         NSLog(@"Success: %@", result);
     }
 }];

调用完成处理程序,但出现 HTTP 错误 #403。我究竟做错了什么?

4

1 回答 1

0

如果完成处理程序返回 HTTP/403 Forbidden,则您的身份验证有问题。您的 Facebook 会话可能无效,或者根本没有打开。请查看Facebook iOS SDK 教程以了解如何建立有效会话。本质上你应该做这样的事情:

static NSString *PublishStreamPermission = @"publish_stream";
[FBSession
    openActiveSessionWithPublishPermissions:@[PublishStreamPermission]
    defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
    completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
        if ([session state] != FBSessionStateOpen) {
            // failed to open a valid session
        } else if ([[session permissions] containsObject:PublishStreamPermission]) {
            // session opened, permissions granted, now you can post
        } else {
            // session opened, but requested permissions not granted
        }
}];
于 2012-11-19T14:31:18.003 回答