android - Query to retrieve json objects from facebook graph api(search) -


i want url this facebook graph api search retrieve data.

when tried using url, gives

{    "error": {       "message": "(#200) must have valid access_token access endpoint",       "type": "oauthexception",       "code": 200    } } 

i using on android. can please guide me in achieving this.

facebook's graph api public until when added access_token.

from documentation explain how create temporary access token. unfortunately, creating in way, need deal sort of job update (i.e. renew existing access token/generate new access token) once in while access_token can able make use of graph api.

most probably, there libraries out there might deal renewing or generating new access token, maybe won't fit app.

so avoid mentioned "problem", found there way have non-expiring access token.

what need following steps:

  1. create facebook account (if don't have 1 or if want create account development purposes)
  2. go @ facebook developers page (register developer, activate account , whatnot)
  3. create new app on facebook developers app page
  4. go app , @ settings, click on edit settings.
  5. go @ sandbox mode , select disabled
  6. on left hand side, settings section, click on advanced.
  7. at authentication section, check app type , select web (if not that)
  8. for final step, go basic section in settings , see 2 app specifics:

    app id , app secret

    you can make use of these 2 codes in order benefit access_token not expire follows: app id|app secret (observe vertical bar between codes)

so can make requests so:

https://graph.facebook.com/search?q=mark&access_token=app_id|app_secret 

observe did not mentioned in url type=user. case, need create expiring access tokens. can create temporary token this:

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

(see access tokens page facebook's documentation). if cannot find solution deal automatically refreshing of access token, can explain did creating background job update once in while:

this return response similar this:

access_token=new_access_token&expires=time_until_it_expires. 

as far remember, able use newly create access token 60 days no problem (it easier me generate new 1 once month making use of cron jobs).

so, having response can simple regex:

access_token=(.*)&expires=(.*) 

and can do:

string newaccesstoken = matcher.group(1); 

replace existing access token in file/db table , you're done.

with access token able make request:

https://graph.facebook.com/search?q=mark&type=user&access_token=app_id|app_secret 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -