我引用以下 link 完成了以下代码创建用于在 Facebook 中上传多张照片的批量请求。
我通过这个 Facebook graph API. 得到了一些在 Facebook 上上传多张照片的解决方案
代码:
NSString *jsonRequest1 = @"{ \"method\": \"POST\", \"relative_url\": \"me/photos\" , \"body\": \"Hello 1\", \"attached_files\": \"file1\" }";
NSString *jsonRequest2 = @"{ \"method\": \"POST\", \"relative_url\": \"me/photos\" , \"body\": \"Hello 2\", \"attached_files\": \"file2\" }";
NSString *jsonRequestsArray = [NSString stringWithFormat:@"[ %@, %@ ]", jsonRequest1, jsonRequest2];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:jsonRequestsArray,@"batch",nil];
[params setObject:UIImagePNGRepresentation(self.image1) forKey:@"file1"];
[params setObject:UIImagePNGRepresentation(self.image2) forKey:@"file2"];
[objFacebook requestWithGraphPath:@"me" andParams:params andHttpMethod:@"POST" andDelegate:self];
现在,当我运行这段代码时,我得到了以下输出。
结果字典在 - (void)request:(FBRequest *)request didLoad:(id)result
(
{
body = "{\"error\":0,\"error_description\":\"File file1 has not been attached\"}";
code = 400;
headers = (
{
name = "HTTP/1.1";
value = "400 Bad Request";
},
{
name = "Content-Type";
value = "text/javascript; charset=UTF-8";
}
);
},
{
body = "{\"error\":0,\"error_description\":\"File file2 has not been attached\"}";
code = 400;
headers = (
{
name = "HTTP/1.1";
value = "400 Bad Request";
},
{
name = "Content-Type";
value = "text/javascript; charset=UTF-8";
}
);
}
)
我不知道这些文件是如何附加的。谁能帮我解决这个问题。
如果我的代码有任何变化,请告诉我。
提前致谢...
最佳答案
我建议您使用 iOS 6 中新集成的 Facebook API 而不是 Facebook 的 API:https://developer.apple.com/videos/wwdc/2012/?id=306所有社交任务都有一个金色的 WWDC 视频。此外,在 iOS 6 中使用新的 API 比使用 Facebook 快得多。
关于iphone - 使用批量请求在 Facebook 上传多张照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10291741/