How to get specific objects based on the ID?

523 views
Skip to first unread message

Alejandro Villamarin

unread,
Nov 22, 2014, 1:44:54 PM11/22/14
to res...@googlegroups.com
Hello people,

I'm trying to fetch individual objects (Posts, StatusMessages and comments based on their respective ID)

For instance, let's say I want the StatusMessage with ID (This is a real one):

316492991876763_320044024854993

I'm doing this:

status = facebookClient.fetchObject(postId, StatusMessage.class);

But I keep on gettign this exception:

SEVERE: service exception:
com.restfb.exception.FacebookGraphException: Received Facebook error response of type GraphMethodException: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api (code 100, subcode null)
    at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1044)
    at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:954)
    at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:887)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:828)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:792)
    at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:371)
    at genesys.facebook_connector.utils.FacebookUtils.processStatusUpdate(FacebookUtils.java:156)
    at genesys.facebook_connector.subscribers.RealtimeUpdatesSubscriber.facebookUpdate(RealtimeUpdatesSubscriber.java:356)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)


Well, first question is....can I query for single objects using the ID? I got the ID from a FB real time update message, so it is legit....

Any clues? Thanks!

Alejandro Villamarin

unread,
Nov 22, 2014, 2:01:34 PM11/22/14
to res...@googlegroups.com
I've debugged the fetchObject a bit and it looks like the final endpoint for that id is this one:

https://graph.facebook.com/316492991876763_320044024854993?access_token=1436810609916235%7CUiQvYRgy-iNqqmyUDlP-B3SeNZ8&format=json

THis returns this

{
   "error": {
      "message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
      "type": "GraphMethodException",
      "code": 100
   }
}

I've tested changing the URL with a user token, instead of the app token used to configure the FacebookClient that executed the fetchObject method and it works....so I guess my question is...can I create a FacebookClient with a user token instead of an app token? If so....any pointers?

Thanks!

Marcel Stör

unread,
Nov 22, 2014, 2:19:33 PM11/22/14
to res...@googlegroups.com
On 22.11.14 20:01, Alejandro Villamarin wrote:
> can I create a FacebookClient with a user token instead of an app token?
> If so....any pointers?

Your question confuses me a bit but I guess you might want to
familiarize yourself with
https://developers.facebook.com/docs/facebook-login/access-tokens first.
I don't know /what/ you already know but if you're stuck with the login
flow also check out
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.2

This http://goo.gl/tGtCS older post is sometimes referred to on this
list if people are stuck with login.

--
Marcel Stör, http://frightanic.com
Couchsurfing: http://www.couchsurfing.com/people/marcelstoer
O< ascii ribbon campaign - stop html mail - http://bit.ly/1sNwXAM

Alejandro Villamarin

unread,
Nov 22, 2014, 2:45:29 PM11/22/14
to res...@googlegroups.com
Hello Marcel,

I think it is clear that using the app token (app Id + app secret ) I'm not able to fetch this data, while if I use a user token in the final url that is used by restFB to fetch an object...it works....so I guess the question is, can I configure the FacebookClient to use this user token instead of the app token? Otherwise I'll end up making my own http request and parsing the response from FB, but it looks kinda awkward that restFB does not provide the means for this

A bit of context might be necessary, I'm not writing an app the requires any user to grant me access to it's pages, user page, etc. I'm getting these user tokens by other means, (basically another app), so I don't need to do any oAuth dance, I already have the user access token that will give me access to those objects I'm trying to fetch, since it is this user the one that owns the page, and I have a user token with manage pages permission. As I said, using that url and a the user token gets me the data...so I'm just wondering if this is possible with restFB and the FacebookClient class

Thanks!

Marcel Stör

unread,
Nov 22, 2014, 2:55:31 PM11/22/14
to res...@googlegroups.com
On 22.11.14 20:45, Alejandro Villamarin wrote:
> the question is, can I configure the FacebookClient to use this user
> token instead of the app token?

Yes. The Javadoc[1] is clear in its brevity:

"accessToken - A Facebook OAuth access token."

Whatever you pass to the FacebookClient is being used for the
'access_token' request parameter.

[1]
http://restfb.com/javadoc/com/restfb/DefaultFacebookClient.html#DefaultFacebookClient-java.lang.String-

Alejandro Villamarin

unread,
Nov 22, 2014, 3:00:58 PM11/22/14
to res...@googlegroups.com
Just for the record guys, I've tested this:

FacebookClient facebookClient = new DefaultFacebookClient("a valid user token here");
status = facebookClient.fetchObject(post_id, StatusMessage.class);

And perfectly works, so yes, it is possible to use any type of token I guess with a FacebookClient...

Bests!
Alejandro


On Saturday, November 22, 2014 7:44:54 PM UTC+1, Alejandro Villamarin wrote:

Rob Mitchell

unread,
Jan 14, 2015, 12:03:11 PM1/14/15
to res...@googlegroups.com
Also, sadly with the new FB API v2.2, Facebook will remove "read_stream" permission so you won't be able to read non-public posts.
Reply all
Reply to author
Forward
0 new messages