php - I pass Facebook different URLs on a website and they return the same data each time? -
i have problem requesting data facebook. have tried few different ways number of likes individual page on website manage, each time send specific url same information back. share , , comment totals same each url pass facebook.
so instance send: http://api.facebook.com/restserver.php?method=links.getstats&urls=http://thiswebsite.com/page21/
or
http://api.facebook.com/restserver.php?method=links.getstats&urls=http://thiswebsite.com/page49/
and same information returned.
i have open graph tags on site , think implemented correctly when pass urls directly show above same results. og tags have on site effecting results facebook returns, if manually passing them facebook?
well have 2 options take. one's overly complicated once have working you'll never have worry it. other takes time requires lot less effort.
i'll start simple one. go https://developers.facebook.com/tools/explorer. once there uid should there delete every thing after including ? , paste in
/accounts?fields=id,name,likes
you have make , access token see data. need manage_pages permission checked on extend permissions tab.
once hit submit , should see in results pages you're admin on uid of page, name , number of likes.
the other way build app handles you. have register facebook , app id them. app can build program gets information using php , or java script
here's sample of php can use.
require "facebook.php"; $config = array( 'appid' => 'app_id', 'secret' => 'app_secret', 'fileupload' => false, // optional 'allowsignedrequest' => false, // optional, should set false non-canvas apps ); $facebook = new facebook($config); $user_id = $facebook->getuser(); if($user_id) { // have user id, logged in user. // if not, we'll exception, handle below. try { $path = '/' .$pageid .'?fields=likes'; $pagedata = $facebook->api($path,'get'); $likes = $pagedata['likes']; } catch(facebookapiexception $e) { // if user logged out, can have // user id though access token invalid. // in case, we'll exception, we'll // ask user login again here. error_log($e->gettype()); error_log($e->getmessage()); } } else { // no user, print link user login $login_url = $facebook->getloginurl(); }
if choose longer route let me know have whole thing built.
Comments
Post a Comment