这是简单的代码
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:
您不能直接将图像上传到墙上,发布到墙上时,您只需将图像链接到它即可。因此,您需要先将UIImage上传到某个地方。您有 2 个选项:
- 上传到您的/某些服务器并发布链接到它的墙帖子。
- 上传到脸书相册。检查图形 API 以执行此操作,这非常简单
我只是看了一下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
参数不是图像本身,而是指向图像的链接?您必须先上传图像,然后将指向图像的链接放入此参数中。
我不确定这是否是您代码中的唯一错误,但可以肯定的是,这是一个主要错误。
将图像导入到项目中,并尝试将 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];
}
}