在我的应用程序中我使用Facebook sdk 3.1并使用它我尝试做墙贴。 使用此代码片段,我可以在Friend Wall和我自己的墙上成功发布图像和消息。我只需更改我/照片和 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 。
所以,请指导我,我做错了什么?,或者我必须为墙贴做些什么。
答案 0 :(得分:7)
这是解决方案,
我将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的墙上。
希望这段代码可以帮助别人。
答案 1 :(得分:0)
我不确定。试试这个:
me?fields=friends.fields(feed)