使用iPhone应用程序上传照片到脸书时出现错误

问题描述:

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

- (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} 

试图通过谷歌搜索建议的吨的可能方法,但没有运气。感谢任何人都可以对此有所了解。提前致谢。

你可以尝试代码如下:

- (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]; 
} 

你指定@在permsissions “publish_stream”(在 'initWithNibname' 的方法)?