2016-04-12 13 views
1

Ich habe 2 Möglichkeiten, Bilder an Facebook zu teilen.mehrere Bilder auf Facebook hochladen mit SLRequest

Das SDK Way (Arbeit perfekt):

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

und SLRequest Weg (nur 1 Bild senden):

+ (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!"); 
      } 
     } 
    }]; 
} 

Ich glaubte, dass, wenn die jeweils in einem mehrteiligen gesendeten Daten funktionieren könnte , aber nein.

Wer hat eine Idee, wie es geht? Vielen Dank.

Antwort

1

Es gibt einige Artikel in den Facebook-Dokumenten, die Ihnen helfen könnten.

https://developers.facebook.com/docs/graph-api/making-multiple-requests

in Ihrem Fall also, müssen Sie ein Feld batch genannt in Ihrer Anfrage senden und jede Datei muss mit einem eindeutigen Namen angebracht werden, damit es nicht durch eine umzuschreiben werden. die Einstellungen für diese Anforderung versucht

[ 
    { 
    "method": "POST", 
    "relative_url": "me/photos", 
    "body": "message=labrys", 
    "attached_files": "file1" 
    }, 
    { 
    "method": "POST", 
    "relative_url": "me/photos", 
    "body": "message=circle", 
    "attached_files": "file2" 
    } 
] 

ich es mit Postbote:

Der Inhalt batch Feld wird eine json sein, in dem Sie den Endpunkt Ihrer Anfrage angeben wird, so etwas wie dieses (minimierte btw) wie folgt aussehen sollte:

image

Sorry für die nicht-Code veröffentlichen, ich bin in Objective-C nicht bewandert, aber ich hoffe, dass Sie die Idee, diese zu bekommen.

+0

Danke Mann. Funktioniert perfekt – jose920405