【问题标题】:iPhone post images to Facebook FeediPhone 将图像发布到 Facebook 订阅源
【发布时间】:2012-06-05 11:14:23
【问题描述】:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               photoDescription, @"message",
                               image, @"image",
                               nil];


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

这就是我将图片上传到 Facebook 的方法。图片已成功上传至 Facebook 'photos'。但我想将图像发布到我的 Facebook 订阅源。所以我尝试了,

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

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

我搜索并使用了不同的方法来解决问题,但找不到任何有用的...

【问题讨论】:

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


    【解决方案1】:

    不确定您的 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];
    

    【讨论】:

    • 我相信这与问题中的解决方案相同。换句话说,它只会发布到用户时间线,而不是新闻源。
    • 编辑了我的答案以利用 Facebook 的对话方法,而不是图形请求。现在无法测试,但希望这就是答案
    • 我刚刚尝试了您的解决方案,但它根本没有将图像发布到 Facebook。我认为feed 对话框也是正确的。我也试过me/feed,但也没有用。
    • 要发布用户的提要,请使用“提要”对话框而不是发布对象。 developers.facebook.com/docs/reference/dialogs/feed
    【解决方案2】:
    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];
    
             }
         }];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多