4

我想从 iphone 上传多张图片到 Facebook。而且我搜索了很多东西并制作了如下代码:但它不起作用。任何帮助将不胜感激。

AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

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

NSString *url1=@"http://uhallnyu.files.wordpress.com/2011/11/green-apple.jpg";

NSString *url2=@"http://scm-l3.technorati.com/12/04/24/67277/apple.gif?t=20120424140104";

NSData *data1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:url1]];

UIImage *img1  = [[UIImage alloc] initWithData:data1];

NSData *data2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:url2]];

UIImage *img2  = [[UIImage alloc] initWithData:data2];

[params setObject:img1 forKey:@"file1"];

[params setObject:img2 forKey:@"file2"];

[[delegate facebook] requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
4

1 回答 1

1

您可以使用以下方法将照片上传到 Facebook:- 您可以使用开关盒从图像文件中读取图像类型并使用 UIImagePNGRepresentation、UIImageJPEGRepresentation 等函数获取图像数据。

NSData *yourImageData= UIImagePNGRepresentation(yourImage);  

初始化字典:-

NSMutableDictionary *mutableDictWithParam= [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Your text", @"message", yourImageWithData, @"theSource", nil];  

最后发帖:-

[facebook requestWithGraphPath:@"/me/photos" andParams:mutableDictWithParam andHttpMethod:@"POST" andDelegate:self]; 

您可以让它循环发送多个图像。

于 2012-05-15T13:06:17.713 回答