0

I am trying to batch upload photos via Facebook javascript API. I did reading the API docuemnt. (https://developers.facebook.com/docs/graph-api/reference/v2.0/page/photos https://developers.facebook.com/docs/graph-api/making-multiple-requests)

I make batch request via the following javascript function:

function batchUploadPhotoOnPage() {
    var pageId = '111222333';
    var pageAccessToken = 'xxxxyyyzzzzzzz';
    FB.api(
        '/',
        'post',
        {
            'batch': [
                  {
                      'method': 'post',
                      'relative_url': pageId+'/photos',
                      'access_token': pageAccessToken,
                      'message': 'Test Upload Photos 1...'+new Date(),
                      'url': 'https://hn85599112.files.wordpress.com/2014/07/girl-photo.jpeg'
                  },
                  {
                      'method': 'post',
                      'relative_url': pageId+'/photos',
                      'access_token': pageAccessToken,
                      'message': 'Test Upload Photos 2...'+new Date(),
                      'url': 'http://www.paopaoche.net/up/2012-5/20125523231510353173.jpg'
                  }
             ]
        },
      function(response) {
          log(response);
      }
    );
}

But it always response an error message:

{
   "error": { 
      "message": "(#324) Requires upload file", 
      "type": "OAuthException", 
      "code": 324
   }
}

I am struggling for this a long time, but still can't figure it out. Please help, if you know where I am wrong. Many thanks! T_T

Aacini
  • 65,180
  • 12
  • 72
  • 108
david_ure
  • 1
  • 1

1 Answers1

0

Have a look at this JSFiddle: http://jsfiddle.net/M8SPH/

Be sure to add your app_id, page_id and page_access_token.

Basically, you got forgot that you have to add a body parameter and URL encode the actual parameters in it:

FB.api(
        '/',
        'POST',
        {
            access_token: pageAccessToken,
            'batch': [
                  {
                      'method': 'POST',
                      'relative_url': pageId+'/photos',
                      'access_token': pageAccessToken,
                      'body': "message=Test Upload Photos 1...&url=https://hn85599112.files.wordpress.com/2014/07/girl-photo.jpeg"
                  },
                  {
                      'method': 'POST',
                      'relative_url': pageId+'/photos',
                      'access_token': pageAccessToken,
                      'body': "message=Test Upload Photos 2...&url=http://www.paopaoche.net/up/2012-5/20125523231510353173.jpg"
                  }
            ]
        },
        function(response) {
            console.log(JSON.stringify(response));
        }
);

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

Tobi
  • 31,405
  • 8
  • 58
  • 90