【问题标题】:Post image on facebook wall using graph api iphone sdk使用graph api iphone sdk在facebook墙上发布图像
【发布时间】:2012-12-22 07:02:35
【问题描述】:

我一直在尝试使用 facebook graph API 在 facebook 上发布照片。验证用户身份后,我正在执行以下操作

        NSMutableDictionary *variables = [[NSMutableDictionary alloc]init];
        [variables setObject:@"some text" forKey:@"message"];
        [variables setObject:@"some link" forKey:@"link"];
        [variables setObject:[UIImage imageNamed:@"icon@2x.png"] forKey:@"picture"];

        NSString *str = @"me/feed";
        NSLog(@"str: %@", str);
        FbGraphResponse *resp = [self.fbGraph doGraphPost:str withPostVars:variables];
        NSLog(@"resp: %@", resp.htmlResponse);

但我的应用程序因抛出异常而崩溃:

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: -[UIImage dataUsingEncoding:]: unrecognized selector sent to instance 0x11545140'

所以有人可以帮助我如何使用图形 API 在 Facebook 墙上发布图片以及一些消息。

【问题讨论】:

标签: iphone ios facebook-graph-api


【解决方案1】:

使用下面给出的代码

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];

//create a UIImage (you could use the picture album or camera too)
//UIImage *picture =selectimage.image;
UIImage *picture =[self scaleAndRotateImage:selectimage.image];

FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];

    [variables setObject:graph_file forKey:@"file"];

    [variables setObject:myPost.text forKey:@"message"];

    FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables];

【讨论】:

  • 谢谢阿曼。它对我来说工作得很好。但是为什么我们需要 scaleAndRotateImage。如果我这样做,它会引发 ARC 错误。无论如何我删除它并直接添加图像。谢谢。
猜你喜欢
  • 2011-06-21
  • 1970-01-01
  • 2011-07-30
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多