Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Failed to post as a Page #163

Open
xtianus opened this issue Jun 17, 2015 · 1 comment
Open

Failed to post as a Page #163

xtianus opened this issue Jun 17, 2015 · 1 comment

Comments

@xtianus
Copy link

xtianus commented Jun 17, 2015

Using spring-social-facebook-2.0.1.RELEASE.jar

When trying to post as a Page admin I get the following error:

(#100) Tried accessing nonexisting field (accounts) on node type (Page)

My code is:

            String accessToken = ... ; // the page access token
            String pageId = ...; // the page id 
            Facebook facebook = new FacebookTemplate(accessToken);
            PageOperations pageOperations = facebook.pageOperations();
            PagePostData pagePostData = new PagePostData(pageId);
            pagePostData.link("http://www.mysite.com/mypage", null, null, null, null);
            pageOperations.post(pagePostData);

The stack trace is:

org.springframework.social.UncategorizedApiException: (#100) Tried accessing nonexisting field (accounts) on node type (Page)
    at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleFacebookError(FacebookErrorHandler.java:91) ~[FacebookErrorHandler.class:2.0.1.RELEASE]
    at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleError(FacebookErrorHandler.java:59) ~[FacebookErrorHandler.class:2.0.1.RELEASE]
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614) ~[RestTemplate.class:4.1.6.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570) ~[RestTemplate.class:4.1.6.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:545) ~[RestTemplate.class:4.1.6.RELEASE]
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:253) ~[RestTemplate.class:4.1.6.RELEASE]
    at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchConnections(FacebookTemplate.java:229) ~[FacebookTemplate.class:2.0.1.RELEASE]
    at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchConnections(FacebookTemplate.java:223) ~[FacebookTemplate.class:2.0.1.RELEASE]
    at org.springframework.social.facebook.api.impl.PageTemplate.getAccounts(PageTemplate.java:61) ~[PageTemplate.class:2.0.1.RELEASE]
    at org.springframework.social.facebook.api.impl.PageTemplate.getAccount(PageTemplate.java:125) ~[PageTemplate.class:2.0.1.RELEASE]
    at org.springframework.social.facebook.api.impl.PageTemplate.getAccessToken(PageTemplate.java:115) ~[PageTemplate.class:2.0.1.RELEASE]
    at org.springframework.social.facebook.api.impl.PageTemplate.post(PageTemplate.java:77) ~[PageTemplate.class:2.0.1.RELEASE]

The log:

o.a.h.impl.execchain.MainClientExec - : Executing request GET /v2.3/me/accounts HTTP/1.1
o.a.h.impl.execchain.MainClientExec - : Proxy auth state: UNCHALLENGED
org.apache.http.headers - : http-outgoing-0 >> GET /v2.3/me/accounts HTTP/1.1
org.apache.http.headers - : http-outgoing-0 >> Accept: application/json, application/*+json
org.apache.http.headers - : http-outgoing-0 >> Authorization: OAuth CAAMLZBlqp0eEBAAmu1eezUeIzQUcTTZCvotVUjZBel6uvBNYscEk8MCtFTnmnPpvGEvtygl1QDclJxK6Y5yaIbJCSatLwONYwFDmyg4cklUTCNl8I6MnMn3zDtbhGXBJSF2oOKj9z1VOogOOzQwZCdcf5PGD0bh9ZAHxeYbYrGzhcZB93jZB32RqwuKEfKcWz8ZD
org.apache.http.headers - : http-outgoing-0 >> Host: graph.facebook.com
org.apache.http.headers - : http-outgoing-0 >> Connection: Keep-Alive
org.apache.http.headers - : http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5 (Java/1.7.0_67)
org.apache.http.headers - : http-outgoing-0 >> Accept-Encoding: gzip,deflate
org.apache.http.wire - : http-outgoing-0 >> "GET /v2.3/me/accounts HTTP/1.1[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "Accept: application/json, application/*+json[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "Authorization: OAuth CAAMLZBlqp0eEBAAmu1eezUeIzQUcTTZCvotVUjZBel6uvBNYscEk8MCtFTnmnPpvGEvtygl1QDclJxK6Y5yaIbJCSatLwONYwFDmyg4cklUTCNl8I6MnMn3zDtbhGXBJSF2oOKj9z1VOogOOzQwZCdcf5PGD0bh9ZAHxeYbYrGzhcZB93jZB32RqwuKEfKcWz8ZD[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "Host: graph.facebook.com[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5 (Java/1.7.0_67)[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
org.apache.http.wire - : http-outgoing-0 >> "[\r][\n]"
org.apache.http.wire - : http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
org.apache.http.wire - : http-outgoing-0 << "WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "(#100) Tried accessing nonexisting field (accounts) on node type (Page)"[\r][\n]"

My take:

the library is trying to get the account details using a page token, which is not a permitted operation.
I guess it should skip this step, which is needed when posting as the user (with a user access token), if the access token is a PAGE access token.

@pjkCochin
Copy link
Contributor

I did some research on this and looks like spring social facebook operations are meant to be user token centric.
Here are some useful answers from craig walls on similar questions on SO -
http://stackoverflow.com/questions/24277094/use-app-access-token-with-spring-social-facebook-to-query-public-pages
http://stackoverflow.com/questions/14748999/how-to-use-facebook-appaccesstoken-with-spring-social

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants