gpt4 book ai didi

iphone - Facebook iOS SDK 3.1 在 friend 墙上发布图片错误

转载 作者:行者123 更新时间:2023-11-28 22:43:36 24 4
gpt4 key购买 nike

我使用的是最新的 Facebook iOS SDK 3.1.1尝试在 friend 墙上发布 UIImage 时出现错误 5(错误:HTTP 状态代码:403)。

如果我尝试将图像张贴到我的墙上,效果很好,但不是我的一个 friend 。

我的代码: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 The request requires higher privileges than provided by the access token. The resource server SHOULD respond with the HTTP 403 (Forbidden) status code and MAY include the "scope" attribute with the scope necessary to access the protected resource.

您必须获得高级权限才能张贴到其他用户的墙上。您需要的权限是@“publish_stream”,它“使您的应用程序能够向用户的流和用户的 friend 的流发布内容、评论和点赞。这是一个超集发布权限,它还包括 publish_actions。”(c)

最新的更改迫使您将所需的权限分为两个级别 - 基本 允许您阅读有关用户的基本信息和高级(发布等)这是权限列表: Extended permissions list

这意味着您必须分两步请求适当的权限。先学基础再求高级。

关于iphone - Facebook iOS SDK 3.1 在 friend 墙上发布图片错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13817590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com