Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Batch Photo Upload iOS

I am having some trouble trying to get the Facebook iOS SDK to batch upload photos. Currently I can upload them one by one, but I would like to batch the requests if possible. I have read this post over and over along with the fb batch docs. Here is what I have thus far.

 Facebook *facebook = [(AppDelegate*)[[UIApplication sharedApplication] delegate] facebook]; 

        NSData *imageData = UIImagePNGRepresentation([imgs objectAtIndex:0]);
   NSString *jsonRequest1 = [NSString stringWithFormat:@"{ \"method\": \"POST\",    \"relative_url\": \"me/photos\", \"attached_files\": \"file1\" }"];
        NSString *jsonRequest2 = [NSString stringWithFormat:@"{ \"method\": \"POST\", \"relative_url\": \"me/photos\", \"attached_files\": \"file2\" }"];
        NSString *jsonRequestsArray = [NSString stringWithFormat:@"[ %@, %@ ]", jsonRequest1, jsonRequest2];


    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:jsonRequestsArray,@"batch",imageData,@"file1",imageData,@"file2" nil];

I am mapping the imageData to the key it is looking for, but I get this response every time.

  {
        body = "{\"error\":{\"message\":\"File batch has not been attached\",\"type\":\"GraphBatchException\"}}";
        code = 400;
        headers =         (
                        {
                name = "WWW-Authenticate";
                value = "OAuth \"Facebook Platform\" \"invalid_request\" \"File batch has not been attached\"";
            },
                        {
                name = "HTTP/1.1";
                value = "400 Bad Request";
            },
                        {
                name = "Cache-Control";
                value = "no-store";
            },
                        {
                name = "Content-Type";
                value = "text/javascript; charset=UTF-8";
            }
        );
    },
        {
        body = "{\"error\":{\"message\":\"File file2 has not been attached\",\"type\":\"GraphBatchException\"}}";
        code = 400;
        headers =         (
                        {
                name = "WWW-Authenticate";
                value = "OAuth \"Facebook Platform\" \"invalid_request\" \"File file2 has not been attached\"";
            },
                        {
                name = "HTTP/1.1";
                value = "400 Bad Request";
            },
                        {
                name = "Cache-Control";
                value = "no-store";
            },
                        {
                name = "Content-Type";
                value = "text/javascript; charset=UTF-8";
            }
        );
    }
)

Any help is very much appreciated.

like image 946
iOSDevSF Avatar asked Jan 05 '12 21:01

iOSDevSF


People also ask

How do I upload multiple photos at once to Facebook?

You can select multiple photos to be uploaded at the same time by holding the CTRL key (or CMD key, for Mac) as you click each photo to upload. Click on the "Open" button on the lower right corner of the small window, and the selected photos will start uploading to Facebook into the selected album.

How do I batch import photos from iPhone?

To select multiple photos, you can tap "Select", then tap all the photos you like. Tap the Share icon at the bottom of your iPhone screen, then tap the AirDrop option. Choose the person or device you want to send the photos to. You may need to tap to accept the files on the receiving device.

How do I upload multiple photos to Facebook from my phone?

Posting Multiple Photos With the Facebook AppIn the status field at the top of the News Feed, tap Photo. Tap the thumbnails of the photos you want to add to the status. Use the Done button to open the preview screen. Add text to your status post, if you want, and select +Album from the options.


1 Answers

Have you tried using the Social framework for iOS 6 to share photos? It allows you to add all the photos and share them.

- (IBAction)postToFacebook:(id)sender {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [controller addURL:[NSURL URLWithString:@"http://www.jinibot.com"]];
        [controller addImage:[UIImage imageNamed:@"socialsharing-facebook-image.jpg"]];

        //add as many images as you want
        [controller addImage:[UIImage imageNamed:@"socialsharing-facebook-image.jpg"]];
        [controller addImage:[UIImage imageNamed:@"socialsharing-facebook-image.jpg"]];
        [controller addImage:[UIImage imageNamed:@"socialsharing-facebook-image.jpg"]];

        [self presentViewController:controller animated:YES completion:Nil];
    }
}
like image 196
kratos Avatar answered Oct 29 '22 14:10

kratos