Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用SLRequest将多个图像上载到facebook_Ios_Objective C_Facebook_Image Uploading_Slrequest - Fatal编程技术网

Ios 使用SLRequest将多个图像上载到facebook

Ios 使用SLRequest将多个图像上载到facebook,ios,objective-c,facebook,image-uploading,slrequest,Ios,Objective C,Facebook,Image Uploading,Slrequest,我有两种方法可以将图片分享到Facebook SDK方式(工作完美): 和请求方式(仅发送1张图像): 我相信,如果每个数据以多部分的形式发送可能会起作用,但不会 有人知道怎么做吗?谢谢。facebook文档中有一些文章可能对您有所帮助 因此,在您的情况下,您需要在请求中发送一个名为batch的字段,并且每个文件都必须附加一个唯一的名称,以便不会被其他文件重写 batch字段的内容将是一个json,您将在其中指定请求的端点,类似这样(简化的btw): 我试过邮递员,该请求的设置如下所示: 很

我有两种方法可以将图片分享到Facebook

SDK方式(工作完美):

和请求方式(仅发送1张图像):

我相信,如果每个数据以多部分的形式发送可能会起作用,但不会


有人知道怎么做吗?谢谢。

facebook文档中有一些文章可能对您有所帮助

因此,在您的情况下,您需要在请求中发送一个名为
batch
的字段,并且每个文件都必须附加一个唯一的名称,以便不会被其他文件重写

batch
字段的内容将是一个json,您将在其中指定请求的端点,类似这样(简化的btw):

我试过邮递员,该请求的设置如下所示:

很抱歉没有发布代码,我不精通目标C,但我希望你能理解这一点

FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];

    NSMutableArray *uploadImages = [[NSMutableArray alloc] init];
    for (UIImage *image in images) {
        FBSDKSharePhoto *sharePhoto = [[FBSDKSharePhoto alloc] init];
        sharePhoto.caption = title;
        sharePhoto.image = image;

        [uploadImages addObject:sharePhoto];
    }
    content.photos = [NSArray arrayWithArray:uploadImages];

    [FBSDKShareAPI shareWithContent:content delegate:self];
+ (void)uploadPhotoToFacebook:(NSMutableArray *)imagesData imageTitle:(NSString *)title account:(ACAccount*)account completionBlock:(shareSocialResponse)completion
{
    SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                    requestMethod:SLRequestMethodPOST
                                                              URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"]
                                                       parameters:@{@"message": title}];

    for (NSData *imageData in imagesData) {
        [facebookRequest addMultipartData:imageData
                                 withName:@"source"
                                     type:@"multipart/form-data"
                                 filename:@"photo!"];
    }
    NSLog(@"facebookRequest %@",facebookRequest);
    facebookRequest.account = account;
    [facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
    {
        if (error) {
            NSLog(@"%@",error.description);

        } else {
            NSDictionary *returnedData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
            NSLog(@"returnedData: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);

            if ([urlResponse statusCode] != 200) {

                dispatch_async(dispatch_get_main_queue(), ^{
                    NSString *errorMessage = @"We could not process your request now";
                    if ([returnedData valueForKeyPath:@"error.message"] != nil) {
                        errorMessage = [returnedData valueForKeyPath:@"error.message"];
                    }
                    completion(NO, errorMessage);
                });
            } else {
                completion(YES, @"Your clip was posted!");
            }
        }
    }];
}
[
  {
    "method": "POST",
    "relative_url": "me/photos",
    "body": "message=labrys",
    "attached_files": "file1"
  },
  {
    "method": "POST",
    "relative_url": "me/photos",
    "body": "message=circle",
    "attached_files": "file2"
  }
]