1

在我的应用程序中,我使用了 Facebook sdk 3.1,并使用它尝试做墙贴。使用此代码片段,我可以成功地将图像和消息贴在朋友墙上和我自己的墙上。我只需更改me/photosfriendId/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

所以请指导我我做错了什么?,或者我必须为墙贴做些什么。

4

2 回答 2

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){}];

我得到了对话框,点击分享成功后在朋友的墙上发帖。

希望这个片段可以帮助别人。

于 2013-05-28T08:46:01.563 回答
0

我不知道。试试这个:

me?fields=friends.fields(feed)
于 2013-05-24T10:17:09.987 回答