gpt4 book ai didi

iphone - 如何从iphone sdk上传多张图片到facebook

转载 作者:可可西里 更新时间:2023-11-01 06:11:55 24 4
gpt4 key购买 nike

我想从 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];

最佳答案

您可以使用以下方式将照片上传到 Facebook:-您可以使用 switch case 从图像文件中读取图像类型,并使用函数 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]; 

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

关于iphone - 如何从iphone sdk上传多张图片到facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10601007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com