开发者

Getting error when using iPhone app to upload photos to facebook

I'm experiencing problem using facebook connect to upload photos to facebook in my iPhone app. I've tried the demo app downloaded from facebook SDK. The code they use to upload photos is as follows:

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

However, no photo is uploaded using this method. I've successfully post to a user's wall using [_facebook dialog:@"stream.publish" andParams:params andDelegate:self] but never succeeded to po开发者_如何转开发st photos. It always give me this error:

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

Tried tonnes of possible method suggested by google search but with no luck. Grateful if anyone can shed some light on this. Thanks in advance.


You can try the Code as below:

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


Did you specify @"publish_stream" in the permsissions (in the 'initWithNibname' method) ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜