【问题标题】:Always get "(#324) Requires upload file" when post image to Facebook with graph API使用图形 API 将图像发布到 Facebook 时总是得到“(#324) 需要上传文件”
【发布时间】:2015-04-07 02:54:02
【问题描述】:

当我将图像发布到facebook时,我总是得到“(#324)需要上传文件”,有很多人问同样错误的问题,他们大多数是使用php sdk,似乎他们通过set解决了这个问题fileUpload 为 true ($facebook->setFileUploadSupport(true);),例如:http://endorkins.com/2010/12/28/facebook-graph-api-upload-photos-requires-upload-file/, Exception when uploading photo with Facebook Graph API

但是我在iOS中直接使用graph api,我找不到在哪里设置这个标志,我在创建相册和上传图片时尝试设置它,但它不起作用。

Facebook 图形 API 参考 (http://developers.facebook.com/docs/reference/api/album/) 说 can_upload 必须为真才能让相册上传照片到相册,我检查了我尝试上传图片的相册,这是真的。

我还拥有 user_photos、friends_photos、publish_stream、publish_actions 的权限。

下面是我发布图片的代码,我花了很多时间但无法修复它,请帮助我!任何帮助表示赞赏。

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/"];

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:url];

NSMutableDictionary *params = [NSMutableDictionary dictionary];

[params setObject:token forKey:@"access_token"];

[params setObject:@"the message" forKey:@"message"];

NSData *imgData = UIImageJPEGRepresentation(self.img, 1.0);

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

NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/photos", albumId] parameters:params];

[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];

//        [request setValue:[NSString stringWithFormat:@"%d", imgData.length]   forHTTPHeaderField:@"Content-Length"];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"%@", error);

        NSLog(@"%@", operation.responseString);

}];

[operation start];

【问题讨论】:

    标签: ios facebook image


    【解决方案1】:

    好的,最后我通过使用 facebook SDK 发布图像解决了这个问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    相关资源
    最近更新 更多