0

我一直在尝试使用 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 墙上发布图像以及一些消息。

4

1 回答 1

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];
于 2013-01-08T12:23:21.970 回答