使用iPhone应用程序将照片上传到Facebook时出错

时间:2010-12-12 15:47:36

标签: iphone objective-c facebook uiimage photo

我在使用facebook连接将照片上传到我的iPhone应用程序中的facebook时遇到问题。我试过从facebook SDK下载的演示应用程序。他们用来上传照片的代码如下:

- (IBAction)uploadPhoto:(id)sender {
    NSString *path = @"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img = [[UIImage alloc] initWithData:data];

    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                img, @"picture",
                                nil];
    [_facebook requestWithMethodName: @"photos.upload"
                           andParams: params
                       andHttpMethod: @"POST"
                         andDelegate: self];
    [img release];
}

但是,使用此方法不会上传照片。我已成功使用[_facebook dialog:@"stream.publish" andParams:params andDelegate:self]发布到用户的墙上,但从未成功发布照片。它总是给我这个错误:

"The operation couldn’t be completed. (facebookErrDomain error 101.)" UserInfo=0x4d80be0 {request_args=(
    {
    key = method;
    value = "photos.upload";
},
    {
    key = sdk;
    value = ios;
},
    {
    key = "sdk_version";
    value = 2;
},
    {
    key = format;
    value = json;
}
), error_msg=Invalid API key, error_code=101}

尝试了谷歌搜索建议的可能方法,但没有运气。如果有人能对此有所了解,感激不尽。提前谢谢。

2 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

- (void)uploadPhoto:(id)sender {
    UIImage *img  = [UIImage imageNamed:@"abc.png"];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:img, @"picture", nil];
    [_facebook requestWithMethodName:@"photos.upload" andParams:params andHttpMethod:@"POST" andDelegate:self];
    [img release];
}

答案 1 :(得分:0)

您是否在permsissions中指定了@“publish_stream”(在'initWithNibname'方法中)?