Facebook PHP SDK: getting "long-lived" access token now that "offline_access" is deprecated -
basic problem: want app able make calls facebook graph api authorized users while user away.
for example, want user (a) authorize app, later want user (b) able use app view info user (a)'s friends. specifically: "work" field. yes, requesting extended permissions (user_work_history, friends_work_history, etc). app has access logged-in user's friends work history, not of friends' work history of other users of app.
here's know already:
- adding
offline_accessscope parameter old way , no longer works. - the new way "long-lived" access tokens, described here. these last 60 days.
i need exchange normal access token new extended token. fb documentation says:
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
here's don't know (and i'm hoping can tell me): how extended (aka "long-lived") access token using facebook php sdk? currently, code looks this:
$facebook->getaccesstoken(); is there such thing this?:
$facebook->getextendedaccesstoken(); if not, should doing?
$accesstoken = $facebook->getaccesstoken(); $extendedaccesstoken = file_get_contents("https://graph.facebook.com/oauth/access_token? client_id={$appid}& client_secret={$secret}& grant_type=fb_exchange_token& fb_exchange_token={$accesstoken}" ); i've tried , doesn't work. error:
warning: file_get_contents(https://graph.facebook.com/oauth/access_token? client_id=#######& client_secret=#########& grant_type=fb_exchange_token& fb_exchange_token=##########) [function.file-get-contents]: failed open stream: http request failed! http/1.0 400 bad request in /... does work differently if switch fql instead of graph api? i've read through facebook documentation many times, php sdk not thoroughly documented , can't find examples of how should work.
i figured out on own. answer pretty anti-climactic. appears newly created apps 60 day access tokens automatically. i'm not sure if dependent on enabling "depricate offline_access" setting in migrations section of app settings. leave on safe.
so @ time of writing this, can use php sdk follows: $facebook->getaccesstoken();
(the reason app wasn't working expected unrelated expiration of access token.)
just 1 more thing, long-lived access token using php sdk should call $facebook->setextendedaccesstoken(); before $facebook->getaccesstoken();
Comments
Post a Comment