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:
- create facebook account (if don't have 1 or if want create account development purposes)
- go @ facebook developers page (register developer, activate account , whatnot)
- create new app on facebook developers app page
- go app , @
settings
, click onedit settings
. - go @
sandbox mode
, selectdisabled
- on left hand side,
settings
section, click on advanced. - at
authentication
section, checkapp type
, selectweb
(if not that) for final step, go
basic
section insettings
, 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:
- you need save current access token (maybe can create manually 1 above mentioned way) in file or maybe better in database table.
once month maybe, need make request using url:
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
Post a Comment