Facebook中的图片分享无效

时间:2012-05-08 13:02:20

标签: iphone objective-c ios facebook

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 @"parth kausik", @"name", 
                                 imageview.image, @"picture",   
                                 nil];

  [facebook requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];

你好,这些代码不起作用。它没有调用请求代理而没有上传任何图片。你有任何想法..

错误即将来临......

error is:Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x6c592d0 {error=<CFBasicHash 0x6c55f70 [0x12a9b38]>{type = mutable dict, count = 3,
entries =>
    2 : <CFString 0x6c56130 [0x12a9b38]>{contents = "type"} = <CFString 0x6c56820 [0x12a9b38]>{contents = "OAuthException"}
    3 : <CFString 0x6c567c0 [0x12a9b38]>{contents = "message"} = <CFString 0x6c56720 [0x12a9b38]>{contents = "An active access token must be used to query information about the current user."}
    6 : <CFString 0x6c59020 [0x12a9b38]>{contents = "code"} = 2500
}
}
Terminating in response to SpringBoard's termination.

2 个答案:

答案 0 :(得分:1)

添加社交框架,然后添加导入类,并添加以下代码

 SLComposeViewController *facebookPostVC =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook ];
[facebookPostVC setInitialText:@"iPhone Application"];
[facebookPostVC addURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",link]]];
[facebookPostVC addImage:[UIImage imageNamed:@"Default.png"]];
[self presentViewController:facebookPostVC animated:YES completion:nil];

注意:这适用于Xcode 4.5

答案 1 :(得分:0)

只需编写参数并将图像设置为以下函数中的描述:

- (void) uploadImageWithName : (NSString*)name
{
    NSString *img = [NSString stringWithFormat:@"%@.png",name];
    UIImage *uploadImage = [UIImage imageNamed:img];//you can get the image on other ways also like imageView.image

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   [fb accessToken], 
                                   @"access_token",nil];

    [params setObject:uploadImage forKey:@"source"];

    [fb requestWithGraphPath:@"me/photos"
                             andParams: params
                         andHttpMethod: @"POST"
                           andDelegate:self];

}