Meh*_*tri 25 iphone objective-c ipad facebook-graph-api
我参考以下链接完成了以下代码,以创建在Facebook上传多张照片的批量请求.
我有一些解决方案可以通过这个Facebook图形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];
Run Code Online (Sandbox Code Playgroud)
现在,当我运行此代码时,我得到以下输出.
结果词典 - (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";
}
);
}
)
Run Code Online (Sandbox Code Playgroud)
我不知道这些文件如何附加..任何人都可以帮我弄清楚这个问题.
我的代码有任何变化,请告诉我.
提前致谢...
Jas*_*son -1
您错误地将二进制文件添加到字典中。看一下Facebook 示例应用程序中的文件上传方法。您应该能够轻松地将 Facebook 的示例代码采用到您的应用程序中。
/**
* Upload a photo.
*/
-(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];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3282 次 |
最近记录: |