posting to / reading from facebook page on behalf off server side facebook app (java & restfb)

69 Views Asked by At

My app has three parts

  • 'A'- A facebook page where automatic posts will be performed by application 'B', so, those posts won't be on behalf of end users but on behalf of app 'B' itself.
  • 'B'- A server side app that will need to user facebook services through restfb the server app will post to 'A' on its behalf the server app will share posts from page 'A' on end user's facebook wall (so, this would be a post on behalf of the user)
  • 'C'- A mobile app that will allow the users to login using facebook this app will only integrate login, at the moment no other interaction with facebook will be done from mobile app.

At the beginning I just configured one facebook app, but then I realized that I actually need two different facebook apps for 'B' and 'C'. Does it makes sense? Is there any way to do this with only one facebook app created on https://developers.facebook.com/apps/?

Then, the main question here is about reading from/posting to 'A' on behalf of 'B' For 'B' I have my appid and app secret, so, I get a restfb client like:

FacebookClient facebookClient = new DefaultFacebookClient(Version.LATEST);
final AccessToken extendedAccessToken = facebookClient.obtainAppAccessToken(appId, appSecret);
facebookClient = extendedAccessToken.getClient();

Then, when trying to post I use the appropriate pageID for the target page 'A'

final FacebookType response = facebookClient
    .publish(pageID + "/feed",
        FacebookType.class,
        Parameter.with("message",
            "this is a test post generated on test" );

This fails with below message

com.restfb.exception.FacebookGraphException: Received Facebook error response of type GraphMethodException: Unsupported post request. Object with ID 'xxxxxxxxxxxxxxx' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api (code 100, subcode 33) 'null - null' at com.restfb.exception.generator.DefaultFacebookExceptionGenerator$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookExceptionGenerator.java:189) at com.restfb.exception.generator.DefaultFacebookExceptionGenerator.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookExceptionGenerator.java:61) at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:823) at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:742) at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:349) at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:369)

Two notes here:

1 - When I create the facebook client in this way

   _ manually get a pageAccessToken on https://developers.facebook.com/tools/explorer/
   _ then use it to get the facebook client
            final FacebookClient facebookClient = new DefaultFacebookClient(pageAccessToken, Version.LATEST);

This way seems to work, I can see the posts getting published on facebook page 'A', but I should not hard code the obtained pageAccessToken on my productive application, so, I'm trying to figure out if getting the token using "appId and appSecret" is correct

2 - My facebook page is still unpublished, so, configuration on page settings has _ Page Visibility: unpublished _ Visitor posts: disable posts by other people on the page

There could be multiple questions here:
      - is this the correct configuration wfor my scenarios while still in development?
      - is there any section to allow my application 'B' to post to my page 'A'
      - which is the right way to deal with the facebook app on testing and production? should I have two different facebook pages? Is there any way to do it with a single facebook page?
0

There are 0 best solutions below