How is FB accesToken generated

145 views
Skip to first unread message

SST

unread,
Mar 31, 2015, 6:27:43 AM3/31/15
to res...@googlegroups.com
GraphReaderExample.java seems to take an accessToken as an argument. How do it generate the accessToken in the first place.


I use the following code to generate an authToken by passing appId, appSecret. 
>>
    public static String getAuthTokenByAuthCode() {
        DefaultFacebookClient dfc = new DefaultFacebookClient();
        AccessToken token = dfc.obtainAppAccessToken(CLIENT_APP_ID, CLIENT_SECRET);
        String accessToken = token.getAccessToken();
        return accessToken;
    }

Norbert Bartels

unread,
Apr 6, 2015, 6:05:56 AM4/6/15
to res...@googlegroups.com
It depends on the type of access token you want to use. 


Can you provide more information?

SST

unread,
Apr 7, 2015, 1:14:25 AM4/7/15
to res...@googlegroups.com
Thanks for your reply. We are using App Access Token for getting facebook posts while public search.

SST

unread,
Apr 7, 2015, 1:16:01 AM4/7/15
to res...@googlegroups.com
Getting the token like the following link https://smashballoon.com/custom-facebook-feed/access-token/


On Monday, April 6, 2015 at 3:35:56 PM UTC+5:30, Norbert Bartels wrote:

Norbert Bartels

unread,
Apr 7, 2015, 11:51:19 AM4/7/15
to res...@googlegroups.com

Okay, so here some explanation of the search. It’s a bit a summary of the facebook api page:

You may search for user, page, event, group, place, placetopic and all ad-types. You cannot search for Posts (only Graph API 1.0 supports search for Post, and 1.0 is only usable until April 30, 2015)!

Using the app access token you can only search across page and place, all other types need a user access token!

SST

unread,
Apr 8, 2015, 1:13:49 AM4/8/15
to res...@googlegroups.com
Thanks for your prompt reply Norbert!!! Then How can I get "user access token" instead of "app access token"? 

Can you provide any sample code for getting User Access Token ?

SST

unread,
Apr 8, 2015, 9:36:45 AM4/8/15
to res...@googlegroups.com
Hi Norbert,
 
I have generated "User Access Token" using the link 

But still am getting the following error.. What did I wrong.. How do I solve this error?? 

com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: An unknown error has occurred. (code 1, subcode null)
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1189)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1104)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1038)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:951)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:914)
at com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:378)

SST

unread,
Apr 10, 2015, 6:43:34 AM4/10/15
to res...@googlegroups.com

appreciate any inputs here

Norbert Bartels

unread,
Apr 10, 2015, 1:24:15 PM4/10/15
to res...@googlegroups.com
Hi SST,

The link you mentioned is about obtaining a long term access token. 

Can you explain which endpoint you want to access? Perhaps this is a useful information, the error message is a bit incomplete.

Cheers
Norbert

SST

unread,
Apr 13, 2015, 12:50:27 AM4/13/15
to res...@googlegroups.com
Hi Norbert,

    We need to fetch the public posts while search.. using the following code,


Connection<Post> messages = fbClient.fetchConnection("search",
                Post.class, Parameter.with("q", keyword),
                Parameter.with("limit", limit), Parameter.with("type", "post"));

We are  getting the access token using the following code,

 public static String getAuthTokenByAuthCode() {
        DefaultFacebookClient dfc = new DefaultFacebookClient();
        AccessToken token = dfc.obtainAppAccessToken(CLIENT_APP_ID, CLIENT_SECRET);
        String accessToken = token.getAccessToken();
        return accessToken;
    }
It throws the following error...

com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: An unknown error has occurred. (code 1, subcode null)
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1189)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1104)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1038)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:951)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:914)
at com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:378)

What am I missing? 

Norbert Bartels

unread,
Apr 13, 2015, 8:10:32 AM4/13/15
to res...@googlegroups.com
With API 2.0 the search type ```post``` is not allowed, so you cannot search for public posts:


...

SST

unread,
Apr 16, 2015, 5:44:50 AM4/16/15
to res...@googlegroups.com
Hi Norbert,
      
         What should I use for search public posts???
...

Norbert Bartels

unread,
Apr 17, 2015, 6:18:04 AM4/17/15
to res...@googlegroups.com
Hi,

Facebook don't want you to search for public posts, so there's nothing. A similar question had been asked yesterday or the day before in the facebook developer group.

Cheers,
Norbert
...
Reply all
Reply to author
Forward
0 new messages