0

I uploaded a photo to Facebook page album using following url

<form id ="uploadForm" method="post" enctype="multipart/form-data">
      <h4>UPLOAD PHOTO</h4>

      <fieldset>
       <input id="name" type="text" />
      </fieldset>
      <fieldset>
       <textarea id="photoDtls"></textarea>
      </fieldset>
      <fieldset>
       <input name ="source" type="file"  />
      </fieldset>
      <input type="submit">
      </form>

And I use the following javascript sdk code

FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
              accessToken = response.authResponse.accessToken;
                  $('#uploadForm').attr('action','https://graph.facebook.com/photos/*page_album_id*?access_token='+accessToken);
                });
          } else if (response.status === 'not_authorized') {
              alert('not autherized');
              FB.login(function(response){
                alert('Permission granted');                
              },{scope: 'email,user_birthday,publish_stream,photo_upload'});
          } else {
              alert('not logged in');
            // the user isn't logged in to Facebook.
          }
         });

I got the response when I uploaded the photo but I don't see the photo is uploaded to my album. Is there a way to check the photo by following id or post id? What could have gone wrong here?

{

    "id": "xxxxxxxxxxxxxxxxxxxxx",
    "post_id": "xxxxxxxx_xxxxxxxxxxxxx"

}
6
  • What do you see when you visit the id or post_id on facebook? Like www.facebook.com/<id or post_id> - is there your photo?
    – Jurik
    Dec 9, 2013 at 9:06
  • graph.facebook.com/_post-id_ gives me { "error": { "message": "Unsupported get request.", "type": "GraphMethodException", "code": 100 } }
    – TV Nath
    Dec 9, 2013 at 9:17
  • Do you use this example: developers.facebook.com/blog/post/498 ? I had a similar problem, but did it with php - cuz I needed to save the picture on server as well: stackoverflow.com/questions/7340949/… - there is the name of image image and not source.
    – Jurik
    Dec 9, 2013 at 9:21
  • 1
    Ahhh now I see the mistake. You want upload a picture to a fanpage album, but you are using an user access token. That won't work. You need the page access token for it.
    – Jurik
    Dec 9, 2013 at 9:26
  • 1
    Good, I posted it as an answer :)
    – Jurik
    Dec 9, 2013 at 9:33

1 Answer 1

1

To upload a photo to a fanpage, you will need to use a fanpage token and not a user token.

To get this token you need to grant manage_pages permission - nothing else. Then you get the fanpage token and save it somewhere on your server, because this you'll need to upload photos to your fanpage.

That means you can't do it with javascript. Because then everyone would see your fanpage access token.

So you'll have to send the photo to your webserver and then upload it to your fanpage album.

4
  • You are right.But when I used application access token as access_token, then I get an error message A user access token is required to request this resource I have asked for scope: 'email,user_birthday,publish_stream,photo_upload'} when connecting with the app
    – TV Nath
    Dec 9, 2013 at 9:40
  • 1
    I updated the answer. Later when I'm at home, I can post an example too - because I've a running app on facebook as page tab that does exactly what you want. But it's broken atm, because I changed my password, but didn't update my access token ;) facebook.com/PowerPhotoUploader/app_300214813374674
    – Jurik
    Dec 9, 2013 at 10:00
  • stackoverflow.com/questions/20490801/… do u have any idea about this? manage_pages only allow the admin users to upload to their pages
    – TV Nath
    Dec 10, 2013 at 9:48
  • 1
    You just need to post on behalf of the admin user. That's why I said you need to save access_token on your server and do the open graph calls with your server and not in browser.
    – Jurik
    Dec 10, 2013 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.