【发布时间】:2013-05-24 10:00:01
【问题描述】:
在我的应用程序中,我使用了 Facebook sdk 3.1,并尝试使用它来做墙贴。 使用此代码片段,我可以成功地将图像和消息发布到朋友墙和我自己的墙上。我只需更改 me/photos 和 friendId/photos。
-(IBAction)postPhoto:(id)sender
{
UIImage *image=[UIImage imageNamed:@"baby.jpg"];
NSArray *frndArray=[[NSArray alloc] initWithObjects:@"Friend ID", nil];
[self postImageOnFriendsWall:image FriendsArray:frndArray];
}
-(void)postImageOnFriendsWall:(UIImage*)image FriendsArray:(NSArray*)friends
{
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
// if we don't have permission to announce, let's first address that
if ([appDelegate.session.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists", nil];
[FBSession setActiveSession:appDelegate.session];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error)
{
if (!error)
{
// 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
{
//post image
for (id<FBGraphUser> user in friends)
{
NSString* szMessage = @"Check out!";
NSString *userID = user;
NSLog(@"trying to post image of %@ wall",userID);
NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init];
[postVariablesDictionary setObject:UIImagePNGRepresentation(image) forKey:@"picture"];
[postVariablesDictionary setObject:szMessage 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];
}
}];
}
}
}
对于消息墙帖子,我使用 me/feed 和它的工作,但对于朋友 friendID/feed 将给我 错误:HTTP 状态代码:403 并在警告框中我得到 com.facebook.sdk 错误 5。
所以请指导我我做错了什么?或者我必须为墙贴做什么。
【问题讨论】:
-
我认为您没有激活所有权限。
-
参见developers.facebook.com/docs/reference/api/publishing - 上面写着“注意:如果您要发布到朋友的时间线或墙上,则必须使用 Feed 对话框。”所以你不能发布friendId/feed。为此,您需要使用提要对话框。
-
@CAbernathy : 谢谢它非常有用
标签: iphone ios facebook facebook-graph-api