php - Get insights from specific page -
i'm trying insights out specific facebook-page, doesn't matter, user request page. can't figured out how it.
i've made code insights user-accesstoken generated in graph explorer.
require 'facebook/src/facebook.php'; $facebook = new facebook(array( 'appid' => '551080774957462', 'secret' => 'f821960b551440b80eecd2dc0a0eff2e', )); //accesstoken graph explorer $user_access_token = "caah1nh3vezaybagbezaemgwwloxkkmuqtutbxt6kao........"; $facebook->setaccesstoken($user_access_token); $facebook->getuser(); //gets pages $user_accounts = $facebook->api("/me/accounts/"); $pageaccesstoken = ""; //find right page foreach ($user_accounts["data"] $page) if ("476015619078252" == $page["id"]) $pageaccesstoken = $page["access_token"]; $facebook->setaccesstoken($pageaccesstoken); $insights = $facebook->api("/476015619078252_$postid/insights");
the problem that, accesstoken graph explorer allways expired after hours .
thanks !
i think can use user token instead of page token
<?php require 'src/facebook.php'; $facebook = new facebook(array( 'appid' => 'app_id_here', 'secret' => 'secret_here', )); $fbid = $facebook->getuser(); $pages = $facebook->api('/me/accounts'); $pageid = $pages['data'][0]['id']; $insights = $facebook->api('/'.$pageid.'/insights'); echo '<pre>'; print_r($insights); exit; ?>
you can pass params since specific date range result..
cheers.
Comments
Post a Comment