iPhone将图片发布到Facebook Feed

时间:2012-05-31 07:55:05

标签: iphone objective-c facebook facebook-graph-api

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               photoDescription, @"message",
                               image, @"image",
                               nil];


[facebook requestWithGraphPath:@"me/photos"
                                    andParams:params
                                andHttpMethod:@"POST"
                                  andDelegate:self];

这就是我将图片上传到Facebook所做的工作。图像成功上传到FaceBook“照片”。但我想将图像发布到我的FaceBook Feed。所以我试过了,

[facebook requestWithGraphPath:@"me/feed"
                                    andParams:params
                                andHttpMethod:@"POST"
                                  andDelegate:self];

但仍然会将图片发布到“照片”中。它没有出现在Feed ...

我搜索并使用不同的方法来解决方案,但我找不到任何有用的东西......

2 个答案:

答案 0 :(得分:0)

不确定params的样子,但试试这个..

UIImage *image = ...// some image.

NSData *imageData= UIImagePNGRepresentation(image);

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                           @"some message", @"message", imageData,@"source", nil];

[facebook dialog:@"feed" andParams:params andDelegate:self];

答案 1 :(得分:0)

UIImage* image=...;
if ([FBSession.activeSession.permissions
         indexOfObject:@"publish_actions"] == NSNotFound) {

        NSArray *permissions =
        [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil];
        [[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
                                              completionHandler:^(FBSession *session, NSError *error) {}];
    }
    else
    {
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setObject:@"Photo post test..." forKey:@"message"];
    [params setObject:UIImagePNGRepresentation(image) forKey:@"picture"];
    //for not allowing multiple hits

        [FBRequestConnection startWithGraphPath:@"me/photos"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                              NSError *error)
     {
         if (error)
         {
             //showing an alert for failure
             UIAlertView *alertView = [[UIAlertView alloc]
                                       initWithTitle:@"Post Failed"
                                       message:error.localizedDescription
                                       delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];
             [alertView show];

         }
         else
         {
             //showing an alert for success
             UIAlertView *alertView = [[UIAlertView alloc]
                                       initWithTitle:@"Post success"
                                       message:@"Shared the photo successfully"
                                       delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];
             [alertView show];

         }
     }];
    }