Вопрос

I am trying to post photos to the user's page timeline with restfb.

My code is like this:

// Create parameters for the call
Collection<Parameter> params = new ArrayList<Parameter>();
params.add(Parameter.with("message", "My Message"));
Parameter postParamsArray[] = params.toArray(new Parameter[params.size()]);
java.net.URL url = new java.net.URL("http://i.istockimg.com/file_thumbview_approve/4739627/2/stock-illustration-4739627-dreidel-game.jpg");
FacebookType publishMessageResponse = facebookClient.publish(facebookWallURL, FacebookType.class,BinaryAttachment.with("dreidel.jpg", url.openStream()), postParamsArray);

However, I see on the timeline only the text: My Message.

The user has the following permissions:

'manage_pages, publish_stream, create_event, photo_upload'

What could be the problem?

Это было полезно?

Решение

facebookWallURL - looks like you're posting to wall. Try posting to the albums instead:

facebookURL = facebookPageId + "/photos";
publishMessageResponse = facebookClient.publish(facebookURL, FacebookType.class, ba, postParamsArray);

as written in this example:
(note "me/videos")
http://restfb.com/

Publishing a Photo (see Graph API documentation)

// Publishing an image to a photo album is easy
// Just specify the image you'd like to upload and RestFB will handle it from there.

FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
  BinaryAttachment.with("cat.png", getClass().getResourceAsStream("/cat.png")),
  Parameter.with("message", "Test cat"));

out.println("Published photo ID: " + publishPhotoResponse.getId());

// Publishing a video works the same way as uploading a photo.

facebookClient.publish("me/videos", FacebookType.class,
  BinaryAttachment.with("cat.mov", getClass().getResourceAsStream("/cat.mov")),
  Parameter.with("message", "Test cat"));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top