我正在使用最新的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<FBGraphUser> 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(禁止)状态代码,并且可以包含“作用域”
属性具有访问受保护资源所需的范围。
您必须获得高级权限才能发布到其他用户的墙。您需要的权限是@“ publish_stream”,它“使您的应用可以向用户的流以及用户的朋友的流中发布内容,评论和喜欢的内容。这是超集发布许可,其中还包括publish_actions。”(c)
最新的更改迫使您将所需的权限划分为两个级别-基本级别,该级别允许您阅读有关用户的基本信息和高级(帖子等)。
以下是权限列表:
Extended permissions list
这意味着您必须分两步要求适当的权限。首先获得基础知识,然后再寻求高级知识。
关于iphone - Facebook iOS SDK 3.1在好友墙上张贴图片错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13817590/