在我的应用程序中,我使用了 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及其工作,但对于FriendfriendID/feed将给我Error: HTTP status code: 403和在警告框中我得到com.facebook.sdk error 5。
所以请指导我我做错了什么?,或者我必须为墙贴做些什么。