0

How do I get facebook realtime updates with android .Basically everytime the user's friendlist changes I need to update the count.I used the code below but I get error msg :

{This method must be called with an app access_token.}, isFromCache:false}

I really appreciate any help.Thanks in Advance.

code:

Bundle params = new Bundle();
params.putString("object", "user");
params.putString("callback_url", "http://example.com/callback/update.php");
params.putString("fields", "friends");
params.putString("verify_token", "1234");
/* make the API call */
new Request(
    session,
    "/12345/subscriptions",
    params,
    HttpMethod.POST,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();

Note: session =fb.getsession();

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
jason
  • 3,932
  • 11
  • 52
  • 123

1 Answers1

1

This error:

"This method must be called with an app access_token."

is quite straight-forward. You just need to make this API call with an App access token, instead of a normal access token (user token). To use it with your call simply add another parameter: access_token and make the call.

The App Access token is nothing but, APP_ID|APP_SECRET, or you can make the call (ref.)-

GET /oauth/access_token?
      client_id={app-id}
      &client_secret={app-secret}
      &grant_type=client_credentials

But beware, its not recommended to expose app access token on the client side, since its like a password of your app.

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • So how or what do I have to change w.r.t the code above.Currently `"/12345/subscriptions"` is the call made how do I execute `GET /oauth/access_token? client_id={app-id} &client_secret={app-secret} &grant_type=client_credentials` and where do I do that ? Thanks for your time really appreciate it. – jason Apr 09 '14 at 07:44
  • I understood what you just said but I dont know where to execute it ? within android code or on graphapi or somewhere else ? Can you please explain more in detail .Thanks again. – jason Apr 09 '14 at 07:51
  • 1. in the params list add `{app-access-token}` for key `access_token`, just like you've added `object` and other keys in the params. 2. What's the issue in making the app access token call? its similar to `/subscriptions` call you have made. – Sahil Mittal Apr 09 '14 at 07:52
  • step 1 : get the app access token ; step 2: use this in your above call. Quite straight forward, isnt it? – Sahil Mittal Apr 09 '14 at 07:52
  • Did you give it a try? – Sahil Mittal Apr 09 '14 at 08:01
  • `Bundle bundle = new Bundle(); bundle.putString("client_id", appId); bundle.putString("client_secret", appSecret); bundle.putString("grant_type", "client_credentials"); Request request = new Request(null, "oauth/access_token", bundle, HttpMethod.GET); Response resp = request.executeAndWait();` – jason Apr 09 '14 at 08:02
  • I am sorry it did not paste the code then .Will this code work .Also what do I have to after getting access_token.Sorry I am trying this for the first time . – jason Apr 09 '14 at 08:03
  • Or can I combine both the calls into one ? – jason Apr 09 '14 at 08:04
  • Or if you could please rewrite the code above with the requirement that would really be awesome.Sorry for the trouble. – jason Apr 09 '14 at 08:05
  • Why are you in panic so much. Relax, and just give it a try. First at least check if its working or not by making the call `/subscription` with a parameter `access_token` and its value will be `app_id|app_secret`. – Sahil Mittal Apr 09 '14 at 08:07
  • I added : `params.putString("access_token", "12|wewee");` and I get this response `GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":null}}, error: null, isFromCache:false} ` – jason Apr 09 '14 at 08:17
  • Hello Sahil.Whats the mistake. Any ideas ? – jason Apr 09 '14 at 08:20
  • There's no error. The call is successful, its just that the response is blank. You should research on this that how subscriptions works exactly. – Sahil Mittal Apr 09 '14 at 08:22
  • Hello Sahil.Can you please have a look at this and tell me what I am doing wrong : https://developers.facebook.com/docs/graph-api/reference/app/subscriptions/ my code is in publishing. – jason Apr 09 '14 at 08:30
  • I would prefer you to ask a new question with your code, explaining that you are getting a blank response. (log the complete response json and show it). Since otehr people can also look into this and may help you. It may take you 5 min but its worth. Ps, you can mark/accept the ans since current issue is solved! I'll look into this problem and will get back to you if find something. – Sahil Mittal Apr 09 '14 at 08:34
  • Cool will do that .Thanks again. – jason Apr 09 '14 at 08:34
  • http://stackoverflow.com/questions/22957148/facebook-realtitme-update-in-android-returns-null check this out:New Q.Thanks Again. – jason Apr 09 '14 at 08:42