使用UIImage作为@“图片”分享Facebook对话框

时间:2012-06-17 09:48:52

标签: objective-c ios facebook cocos2d-iphone

这是简单的代码

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:

3 个答案:

答案 0 :(得分:5)

您无法直接将图片上传到墙上,在发布到墙上时,只需将图片链接到墙上即可。 所以,你需要先在某处上传UIImage。您有两个选择:

  1. 上传到您/某个服务器并发布链接到它的墙贴。
  2. 上传到脸谱相册。检查graph API关于这样做,这非常简单

答案 1 :(得分: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参数不是图像本身而是图像链接?您必须先上传图片,然后将链接添加到此参数中。

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

答案 2 :(得分:-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];
    }
}