I can't get any value from php Facebook graph api -
this full code.
// include required files form facebook sdk require_once( 'facebook/httpclients/facebookhttpable.php' ); require_once( 'facebook/httpclients/facebookcurl.php' ); require_once( 'facebook/httpclients/facebookcurlhttpclient.php' ); require_once( 'facebook/entities/accesstoken.php' ); require_once( 'facebook/entities/signedrequest.php' ); require_once( 'facebook/facebooksession.php' ); require_once( 'facebook/facebookredirectloginhelper.php' ); require_once( 'facebook/facebookrequest.php' ); require_once( 'facebook/facebookresponse.php' ); require_once( 'facebook/facebooksdkexception.php' ); require_once( 'facebook/facebookrequestexception.php' ); require_once( 'facebook/facebookotherexception.php' ); require_once( 'facebook/facebookauthorizationexception.php' ); require_once( 'facebook/graphobject.php' ); require_once( 'facebook/graphsessioninfo.php' ); use facebook\httpclients\facebookhttpable; use facebook\httpclients\facebookcurl; use facebook\httpclients\facebookcurlhttpclient; use facebook\entities\accesstoken; use facebook\entities\signedrequest; use facebook\facebooksession; use facebook\facebookredirectloginhelper; use facebook\facebookrequest; use facebook\facebookresponse; use facebook\facebooksdkexception; use facebook\facebookrequestexception; use facebook\facebookotherexception; use facebook\facebookauthorizationexception; use facebook\graphobject; use facebook\graphsessioninfo; // start session session_start(); // init app app id , secret facebooksession::setdefaultapplication( 'key','secret' ); // login helper redirect_uri $helper = new facebookredirectloginhelper( 'site_name.php' ); // see if existing session exists if ( isset( $_session ) && isset( $_session['fb_token'] ) ) { // create new session saved access_token $session = new facebooksession( $_session['fb_token'] ); // validate access_token make sure it's still valid try { if ( !$session->validate() ) { $session = null; } } catch ( exception $e ) { // catch exceptions $session = null; } } if ( !isset( $session ) || $session === null ) { // no session exists try { $session = $helper->getsessionfromredirect(); } catch( facebookrequestexception $ex ) { // when facebook returns error // handle better in production code print_r( $ex ); } catch( exception $ex ) { // when validation fails or other local issues // handle better in production code print_r( $ex ); } } // see if have session if ( isset( $session ) ) { // save session $_session['fb_token'] = $session->gettoken(); // create session using saved token or new 1 generated @ login $session = new facebooksession( $session->gettoken() ); // graph api request user data $request = new facebookrequest( $session, 'get', '***/1458726944414455/likes***' ); $response = $request->execute(); // response $graphobject = $response->getgraphobject()->asarray(); // print profile data echo '<pre>' . print_r( $graphobject, 1 ) . '</pre>'; // print logout url using session , redirect_uri (logout.php page should destroy session) echo '<a href="' . $helper->getlogouturl( $session, 'site_name/logout.php' ) . '">logout</a>'; } else { // show login url echo '<a href="' . $helper->getloginurl( array( 'email', 'user_friends' ) ) . '">login</a>'; }
in * * section above, if put facebook page names or 'me', code works fine. when insert '/1458726944414455/likes' this, can't value results array ( )
what makes me mad is, /1458726944414455/likes works fine in https://developers.facebook.com/tools/explorer, graph api explorer. think token scope not different in graph api explorer , own website.
what wrong? searched every website wrote facebook php sdk or graph api, using same code me.
is because didn't review submission form? using default app status & review. thought doesn't matter because don't login facebook that. wrong? please me.
thank reading.
Comments
Post a Comment