3

I'm trying to publish a photo to a page using the following:

FacebookClient client = new DefaultFacebookClient(destinationAccessToken);
BinaryAttachment attachment = BinaryAttachment.with(imageName, imageInputStream);
Photo photoResponse = client.publish("/me/photos", Photo.class, attachment);

I'm getting the following response:

{
    "error": {
        "message":"An unexpected error has occurred. Please retry your request later.",
        "type":"OAuthException",
        "code":2
    }
}

When I use the same code to publish to a user wall it works fine.

I've also tried posting to "/{page id}/photos" with the same result.

The destination access token has the manage_pages, photo_upload, publish_actions, and publish_stream permissions amongst others.

What am I doing wrong here?

UPDATE:

If I publish to a predetermined album using "/{album id}/photos" then it works. Quoting this Facebook developer blog post:

https://graph.facebook.com/USER_ID/photos - The photo will be published to an album created for your app. We automatically create an album for your app if it does not already exist. All photos uploaded this way will then be added to this same album.

So is this behavior broken for pages? Or am I misunderstanding something here?

UPDATE 2:

I found a bug report for this issue, so I'm posting that as an answer.

UPDATE 3:

The bug seems to have been resolved.

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
  • See [constructor API](http://restfb.com/javadoc/com/restfb/DefaultFacebookClient.html#DefaultFacebookClient%28java.lang.String%29), add a parameter accessToken to the DefaultFacebookClient. Or use a public path (?). – Joop Eggen May 07 '12 at 01:17
  • @JoopEggen - I'm not sure what you mean - can you rephrase? Please post as an answer if it's meant to be. – Paul Bellora May 07 '12 at 01:23
  • `new DefaultFacebookClient(getAccessToken())` but I am afraid you've got none. You will have to await a real answer. It is a session related timeout for allowing access. I am not a genuine facebook programmer. – Joop Eggen May 07 '12 at 01:30
  • @JoopEggen - I've got none what? Are you saying the access token is expired? – Paul Bellora May 07 '12 at 01:51
  • You did not provide one, and hence received an OAuth exception. I wonder why nobody more knowledgeable as I answered yet. – Joop Eggen May 07 '12 at 02:09
  • @JoopEggen - I am providing one: `new DefaultFacebookClient(destinationAccessToken)` where `destinationAccessToken` is the access token for the page. – Paul Bellora May 07 '12 at 02:10

1 Answers1

3

I found the Facebook bug report corresponding to this behavior:

http://developers.facebook.com/bugs/355536551171535

So it would seem I'm not doing anything wrong. I guess the temporary workaround would be to check for a predetermined album and create it if necessary, then publish to it. (Note that the user_photos permission is not needed for this workaround, since albums/photos on pages are always public).

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181