0
votes

This code gives me a short-lived Access Token -

AccessToken ac = AccessToken.getCurrentAccessToken();

From Facebook documentation, I found out the Graph Request endpoint to exchange a short-lived access token for a long-lived one -

https://graph.facebook.com/oauth/access_token?             
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN

On using this on the Facebook Graph API explorer, it is giving me a JSON like this -

{
  "og_object": {
    "id": "xxxx027724271xxxx",
    "type": "website",
    "updated_time": "2015-08-13T21:32:57+0000",
    "url": "https://graph.facebook.com/oauth/access_token"
  },
  "share": {
    "comment_count": 1,
    "share_count": 100
  },
  "id": "https://graph.facebook.com/oauth/access_token"
}

But how do I get the new long-lived access token ?

1
It will be returned as a text formatted in the same way as a URL query string, or a JSON object (from API v2.3 on). Did you also read that this call should only be made from a server (since it contains your app secret, and that should never be included in client-side code)?CBroe
Ok. Thanks. Got it. Yes i read that. I should call it from a server.Ronn
Its not giving the required JSON. See I have updated the question with the JSON it is giving.Ronn
I think Graph API Explorer is not equipped to handle this endpoint. Call the URL as shown above directly in your browser, then you should get a proper response.CBroe
Yes. Just now I tried it. It gives access token in browser.Ronn

1 Answers

-1
votes

You have to use for that ProfileTracker in your code, like

profileTracker = new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(Profile oldProfile,
                Profile currentProfile) {
            if (currentProfile != null && is_in_reg == false) {
                GraphRequest request = GraphRequest.newMeRequest(
                        AccessToken.getCurrentAccessToken(),
                        new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject object,
                                    GraphResponse response) {
}
                        });

                Bundle parameters = new Bundle();
                parameters.putString("fields",
                        "id,name,email,first_name,last_name,picture.width(150),gender,birthday");
                request.setParameters(parameters);
                request.executeAsync();
            }

            //stopTracking();
        }
    };

    profileTracker.startTracking();