title: how to programmatically post on facebook page with spring social?
body: <p>I'm desperately trying to make automatic posts on a facebook <strong><em>page</em></strong> (brand page, and not a user wall). I'm using spring social as framework.</p>
  
  <p>The idea is the following: I've a web app using spring social and I want to be able to post status <strong><em>programatically</em></strong> on the related facebook brand page. The brand page is this kind of page people "like", something similar as <a href="https://www.facebook.com/cocacola" rel="nofollow">https://www.facebook.com/cocacola</a></p>
  
  <p>I tried the following:
  1. get an access token of a valid user with admin right on the page
  2. get access (how?) to the page, and post on that page. Maybe via pageoperation? or something...</p>
  
  <p>I'm stuck on the 1st step, and I was not able to try the 2nd step. For the 1st step, I have:</p>
  
  <pre><code>FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory("clientid", "secretkey");
  OAuth2Operations op = connectionFactory.getOAuthOperations();
  
  OAuth2Parameters params = new OAuth2Parameters();
  </code></pre>
  
  <ul>
  <li>what should I put as parameters? I guess I've to define a scope, right?</li>
  <li>which one will be okay to post on that page?</li>
  </ul>
  
  <p>Then, I'm supposed to get an access token for the admin user, as follows:</p>
  
  <pre><code>AccessGrant ag = op.exchangeCredentialsForAccess("username", "password", params);
  
  accessToken = ag.getAccessToken();
  </code></pre>
  
  <p>Here I'm supposed to have an access token for a user in such a way that the user does not need to input himself the username/password via the facebook login page. However, it doesn't work. I've the following exception:</p>
  
  <blockquote>
    <p>WARN : org.springframework.web.client.RestTemplate - POST request for "<a href="https://graph.facebook.com/oauth/access_token" rel="nofollow">https://graph.facebook.com/oauth/access_token</a>" resulted in 400 (Bad Request); invoking error handler</p>
    
    <p>Oct 23, 2013 9:57:59 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [appServlet] in context with path [/myapp] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request] with root cause
    org.springframework.web.client.HttpClientErrorException: 400 Bad Request</p>
  </blockquote>
  
  <p>I would appreciate if you can post a fully functional proof of concept (I found elements of answer out there, but I didn't manage to make it work...).</p>
  
  <p>Thanks for your help!</p>