2013-01-08 154 views
0

我一直在尝试使用facebook图形API在Facebook上发布照片。验证用户后,我做的是通过抛出异常以下使用图形api在Facebook墙上发布图像iphone sdk

 NSMutableDictionary *variables = [[NSMutableDictionary alloc]init]; 
     [variables setObject:@"some text" forKey:@"message"]; 
     [variables setObject:@"some link" forKey:@"link"]; 
     [variables setObject:[UIImage imageNamed:@"[email protected]"] 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' 

所以有些人可以帮我我如何在Facebook上墙一些消息一起张贴图片使用图形API。

+0

可能给定的复制http://stackoverflow.com/questions/3990433/facebook-photos-upload-crash-in-facebook-api –

+0

这是使用图形API?如果是的话,我可以在哪里找到FBRequest? – Gani414

+0

是的,它是.https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequest/ –

回答

0

使用下面的代码

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]; 
+0

谢谢阿曼。它对我来说工作得很好。但为什么我们需要scaleAndRotateImage。如果我这样做,它会抛出一个ARC错误。任何方式我删除并直接添加图像。谢谢。 – Gani414

相关问题