Facebook iOS SDK 3.1在朋友墙上发布图片错误

我正在使用最新的Facebook iOS SDK 3.1.1,同时试图在朋友墙上发布UIImage我收到错误5(错误:HTTP状态代码:403)。

如果我试图将图像发布到我的墙上它运作良好,但不是我的一个朋友。

我的代码:1。在发布之前我正在检查用户是否拥有正确的权限,当他正在制作时

-(void)postImageOnFriendsWall:(UIImage*)image FriendsArray:(NSArray*)friends { // if we don't have permission to announce, let's first address that if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) { [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) { if (!error) { // re-call assuming we now have the permission [self postImageOnFriendsWall:image FriendsArray:friends]; } else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } }]; } else { // can post image for (id user in friends) { NSString *userID = user.id; NSLog(@"trying to post image of %@ wall",userID); NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init]; [postVariablesDictionary setObject:UIImagePNGRepresentation(image) forKey:@"picture"]; [postVariablesDictionary setObject:@"my image" forKey:@"message"]; [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID] parameters:postVariablesDictionary HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (error) { //showing an alert for failure UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Facebook" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } else { //showing an alert for success UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"Shared the photo successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } }]; } } } 

如果我改变的话

startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID]

 startWithGraphPath:[NSString stringWithFormat:@"me/photos",userID] 

它工作正常。

我究竟做错了什么? 我一直在努力寻找答案,但没有任何帮助。 谢谢!

发生这种情况是因为您的权限级别不足。 正如FB文档所说:

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

您必须获得高级权限才能发布到其他用户的墙上。 您需要的权限是@“publish_stream”,它“允许您的应用程序将内容,评论和喜欢发布到用户的流和用户的朋友的流。这是一个超集发布权限,其中还包括publish_actions。”(c)

最新的更改会强制您将所需权限划分为两个级别 – 基本允许您阅读有关用户和高级 (post等)的基本信息。此处的权限列表: 扩展权限列表

这意味着您必须在两个步骤中请求适当的权限。 首先获得基本,然后要求提前。

你必须检查你的Facebook应用程序ID有时问题创建与它.Cos我有同样的问题发布墙给我的朋友墙但更改Facebook应用程序ID和它的工作完美。