1

这是简单的代码

UIImage *ScreenShot = [self getScreenshot];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Name", @"name",
                               @"Caption.", @"caption",
                               @"Description.", @"description",
                               @"www.example.com", @"link",
                               ScreenShot, @"picture",               
                               nil];

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

当我编译它得到这个消息

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x1288bb90' *** First throw call stack:
4

3 回答 3

5

您不能直接将图像上传到墙上,发布到墙上时您可以将图像链接到它。因此,您需要先将 UIImage 上传到某个地方。您有 2 个选项:

  1. 上传到您/某些服务器并发布链接到它的墙帖。
  2. 上传到 Facebook 相册。检查有关执行此操作的图形 API,这非常简单
于 2012-06-17T10:56:17.567 回答
1

我刚刚查看了 Facebook API,以了解您在这里做什么。在我看来,这

http://www.facebook.com/dialog/feed?
  app_id=123050457758183&
  link=http://developers.facebook.com/docs/reference/dialogs/&
  picture=http://fbrell.com/f8.jpg&
  name=Facebook%20Dialogs&
  caption=Reference%20Documentation&
  description=Using%20Dialogs%20to%20interact%20with%20users.&
  redirect_uri=http://www.example.com/response

清楚地说明 Facebook 想要你做什么。您是否看到picture参数不是图像本身而是图像的链接?您必须先上传图片,然后将图片的链接放入此参数。

我不确定这是否是您代码中唯一的错误,但它肯定是一个主要错误。

于 2012-06-17T10:15:00.230 回答
-1

将图像导入您的项目并尝试将 UIImage *ScreenShot = [self getScreenshot] 行更改为: UIImage *ScreenShot = [UIImage imageNamed:@"yourimage.png"];

如果它有效,您的“getScreenshot”方法可能有问题。

我将它用于我的应用程序:

    UIImage *ImageView = [UIImage imageNamed:@"anImage.png"];
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       ImageView, @"picture",@"Name", @"name",
                                       nil];

         //Let's post it
         [facebook requestWithGraphPath:@"me/photos"
         andParams:params
         andHttpMethod:@"POST"
         andDelegate:self];


-(void)request:(FBRequest *)request didLoad:(id)result{
    if ([result objectForKey:@"id"]) {


        UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Your image has been posted on your wall!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [al show];
        [al release];
    }
}
于 2012-06-17T10:07:38.023 回答