iOS FacebookSDK图片分享

时间:2015-11-06 12:22:49

标签: ios facebook

我使用以下代码将图像从iOS上传到Facebook。

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"MY TEST MSG..." forKey:@"message"];
[params setObject:UIImagePNGRepresentation(self.editImageView.image) forKey:@"picture"];


[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            NSLog(@"uploaded");
        } else {
            NSLog(@"Graph API Error: %@", [error description]);
        }
}];

我的应用程序卡住了几分钟并显示错误消息。 谁能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];
UIImage *picture = FilterImage;
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:@"file"];
[variables setObject:[NSString stringWithFormat:@"Hello testin"] forKey:@"message"];
[fbGraph doGraphPost:@"me/photos" withPostVars:variables];
NSLog(@"Now log into Facebook and look at your profile & photo albums...");