【问题标题】:How to upload multiple images to facebook from iphone sdk如何从 iphone sdk 将多个图像上传到 facebook
【发布时间】:2012-05-15 12:47:51
【问题描述】:

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

【问题讨论】:

    标签: iphone objective-c ios ipad ios5


    【解决方案1】:

    您可以使用以下方式将照片上传到 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]; 
    

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

    【讨论】:

    • 我想发布多张图片。我已成功将单张图片上传到 Facebook。但我在上传多张照片时遇到了问题。
    • 一张一张循环发送图片可能会导致 Facebook 帐户暂时被暂停。因为 FB 可能会将其视为垃圾邮件发布
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    相关资源
    最近更新 更多