Confused new user of RestFB examples

457 views
Skip to first unread message

Brian McCullough

unread,
May 18, 2014, 2:31:17 PM5/18/14
to res...@googlegroups.com
Over the past week or so, I have been exploring RestFB, with little success.

I downloaded RestFB 1.6.14 and have been working with that.

I have been able to compile the code, and, after reading the instructions a couple of times, found the examples.

However, as is in the instructions, I saw that I needed an Access Token. 

Before I got that, I tried making a copy of the Reader Example, removing the Access Token parameter.  No success.  In general, the errors that I am seeing are something like: "User not logged in."

I then went back did two things.  At first, I created a new Application, but that didn't seem right.  After re-reading the instructions, I went to the FB Graph API section, and obtained an Access Token from there.

However, the response here is, as always, unsuccesful.

When I try running ant-reader-example with the very long Access Token string, I get:

ant run-reader-examples "-Daccess_token=CAAC ... very long Access Token string ... AZDZD"
Buildfile: /home/bdmc/projects/restfb-1.6.14/source/example/build.xml

compile:
     [echo] Compiling examples...
    [javac] /home/bdmc/projects/restfb-1.6.14/source/example/build.xml:28: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

run-reader-examples:
     [java] * Fetching single objects *
     [java] May 14, 2014 11:40:20 PM com.restfb.DefaultWebRequestor executeGet
     [java] FINE: Making a GET request to https://graph.facebook.com /me?access_token=CAACE ... very long Access Token string ... AZDZD&format=json
     [java] May 14, 2014 11:40:21 PM com.restfb.DefaultWebRequestor executeGet
     [java] FINE: Facebook responded with HTTP status code 400 and response body: {"error":{"message":"Error validating access token: The session is invalid because the user logged out.","type":"OAuthException","code":190,"error_subcode":467}}
     [java] Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Error validating access token: The session is invalid because the user logged out. (code 190, subcode 467)
     [java]     at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:964)
     [java]     at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:885)
     [java]     at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:824)
     [java]     at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:765)
     [java]     at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:729)
     [java]     at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:306)
     [java]     at com.restfb.example.GraphReaderExample.fetchObject(GraphReaderExample.java:101)
     [java]     at com.restfb.example.GraphReaderExample.runEverything(GraphReaderExample.java:83)



This is done at a command line, in a Ubuntu 13.10 system, running Java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)



Any suggestions, or anything that I can provide to help you guide me in the right direction?



Thank you,
Brian

Siddhartha Biswas

unread,
Jul 5, 2014, 1:51:40 PM7/5/14
to res...@googlegroups.com
Hi Brian,

Don't know whether you have already succeeded or not...I am using same Java version only my OS is Oracle Linux instead of Ubuntu...The way I did the connection is..

Assumption: You have already registered an app in FB

Step 1: Obtain an authentication id:
Go to :
https://developers.facebook.com/tools/accesstoken/
You will get an User Token..Click the debug button next to it. The debug page opens which will show that the user token just generated will last for an hour only.
I am naming this short lived access token as SHORT_LIVED_ACCESS_TOKEN.

Step 2: Get an access token which is valid for 2 months
with the newly generated SHORT_LIVED_ACCESS_TOKEN, try to access this URL
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=SHORT_LIVED_ACCESS_TOKEN

You will get an access token which is now 2 month valid. I call it PERM_ACCESS_TOKEN

Step 3:
 In your java code:

LegacyFacebookClient facebookClient;

//Renew access token every time   
AccessToken accessToken = new DefaultFacebookClient().obtainExtendedAccessToken(APP_ID,APP_SECRET,PERM_ACCESS_TOKEN);

FacebookClient facebook = new DefaultFacebookClient(accessToken.getAccessToken());

PS:
I have started Java coding again after 7 long years...So it may happen that the above code may have potential memory leaks. Please forgive me for that.

Regards,
Siddhartha Biswas
Reply all
Reply to author
Forward
0 new messages