我想从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];
答案 0 :(得分: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];
您可以循环播放多个图像。