在我的应用程序中,我使用了Facebook sdk 3.1,并尝试使用它进行贴墙。
使用此代码段,我可以成功地在 friend 墙上和我自己的墙上张贴图像和消息。我只需更改我/照片和friendId /照片。
-(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];
}
}];
}
}
}
对于Message wall post,我使用了 me / feed 及其工作,但是对于Friend ,friendID / feed 将给我错误:HTTP状态码:403 ,在警报框中,我得到了 com.facebook.sdk错误5 。
所以,如果我做错了什么,请指导我?或我在墙上留言时要做的事情。
最佳答案
这是解决方案,
我将FB SDK 3.1更新为3.2,然后导入
#import <FacebookSDK/FacebookSDK.h>
然后更新
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {}];
代替
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error){}];
并更新
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"FRIEND ID", @"to",
@"text change", @"caption",
@"this is test message on ur wall", @"description",
@"https://website.com/share", @"link",
@"http://website.com/iossdk_logo.png", @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{}];
代替
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID] parameters:postVariablesDictionary HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error){}];
我得到了对话框,然后单击共享后成功在FRIEND的墙上发布。
希望此摘要可以帮助其他人。
关于iphone - 在Friend Wall发表期间Facebook返回com.facebook.sdk错误5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16732352/