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

发布于 2024-10-07 16:31:53 字数 1365 浏览 1 评论 0原文

我在 iPhone 应用程序中使用 facebook connect 将照片上传到 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 dial:@"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}

尝试了谷歌搜索建议的大量可能的方法,但没有运气。如果有人能阐明这一点,我将不胜感激。提前致谢。

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 post 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生池水覆流年 2024-10-14 16:31:53

您可以尝试如下代码:

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

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];
}
叹倦 2024-10-14 16:31:53

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文