php - facebook graph api not work from 2.2 to 2.3 -


because it's due date graph api 2.2, i'm trying fix graph api using v2.3 discover api request response nothing when use 2.3, can not found update in upgrade document. example:

https://graph.facebook.com/v2.3/{$user_id}?date_format=u&fields=albums.order(reverse_chronological).limit(100).offset(0){id,count,name,created_time} 

will return nothing if use 2.3. , can't user's birthday when call:

https://graph.facebook.com/v2.3/{$user_id} 

it's return name , live location. in v2.2, include birthday profile.

i use facebook sdk 3.2.2 because php version 5.3. there update don't know? thanks.

i have found problem myself. it's because sdk 3.2.2. facebook update (from changelog api version 2.3):

[oauth access token] format - response format of https://www.facebook.com/v2.3/oauth/access_token returned when exchange code access_token return valid json instead of being url encoded. new format of response {"access_token": {token}, "token_type":{type}, "expires_in":{time}}. made update compliant section 5.1 of rfc 6749.

but sdk recognize response array(in getaccesstokenfromcode function):

$response_params = array(); parse_str($access_token_response, $response_params); if (!isset($response_params['access_token'])) {   return false; } return $response_params['access_token']; 

this not user access token correctly, , can't user's data. should update function parse data json:

$response = json_decode($access_token_response); if (!isset($response->access_token)) {   return false; } return $response->access_token; 

then of function work usual.


additionally, must make similar changes setextendedaccesstoken(). otherwise, app won't able extend access tokens. code below demonstrates how upgrade function.

  /**    * extend access token, while removing short-lived token might    * have been generated via client-side flow. http://bit.ly/ b0pt0h    * workaround.    */   public function setextendedaccesstoken() {     try {       // need circumvent json_decode calling _oauthrequest       // directly, since response isn't json format.       $access_token_response = $this->_oauthrequest(         $this->geturl('graph', '/oauth/access_token'),         $params = array(           'client_id' => $this->getappid(),           'client_secret' => $this->getappsecret(),           'grant_type' => 'fb_exchange_token',           'fb_exchange_token' => $this->getaccesstoken(),         )       );     }     catch (facebookapiexception $e) {       // user revoked authorization.       // in event, don't have access token, so.       return false;     }      if (empty($access_token_response)) {       return false;     }      //version 2.2 , down (deprecated).  more info, see http://stackoverflow.com/a/43016312/114558     // $response_params = array();     // parse_str($access_token_response, $response_params);     //     // if (!isset($response_params['access_token'])) {     //   return false;     // }     //     // $this->destroysession();     //     // $this->setpersistentdata(     //   'access_token', $response_params['access_token']     // );      //version 2.3 , up.     $response = json_decode($access_token_response);     if (!isset($response->access_token)) {       return false;     }      $this->destroysession();      $this->setpersistentdata(       'access_token', $response->access_token     );   } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -