1
2011
How to get access token and ID for fan page using graph api (facebook)
This is my another blog of my HOW TO series for facebook graph api with php.
In facebook graph api, you can get any information by the help of user id, its access token and particular permission…
Today lets take a look that how we can play with the facebook api to get information related to a fan page…
For fan page, first of all we need manage page permission from user. Then second noticable this is that fan page has its own ID and ACCESS TOKEN, so if we want to do something with fan page remotely like getting or posting anything to fan page then we surely need its ID, its ACCESS TOKEN and manage page permission from user…
Today I will make you understand that how we can get page id and its access token from facebook with facebook graph api php..
Lets suppose that we are using facebook graph api php sdk..
Below is the function that make facebook object of current user and call facebook and gets all the pages, ids and its access token, whom user is admin…
function get_pages_token()
{
$fb = new Facebook(array(
'appId' => app_id,
'secret' => app_secret,
'cookie' => true, // enable optional cookie support
));
$fan_pages = array();
$temp_pages = $fb->api('/'.$fb->user.'/accounts','GET',array('access_token'=>$fb->session_key));
if(count($temp_pages['data']) > 0)
{
foreach($temp_pages['data'] as $page)
{
if($page["category"] != "Application")
$fan_pages[$page['id']] = $page['access_token'];
}
}
return $fan_pages;
}
This function will return an array with ID as key and access token as value for all the fan pages whom user is admin.
Hope this will help ![]()
Enjoy
Related Posts
7 Comments + Add Comment
Leave a comment
Recent Comments
- liberty reserve on FBJS ( Intro to facebook javascript )
- Landscaping Hockessin on FBJS ( Intro to facebook javascript )
- landscaping Hockessin de on Difference between Article and Press Release writing
- ocean city hotels on FBJS ( Intro to facebook javascript )
- wilmington delaware real estate on Difference between Article and Press Release writing
An article by Muhammad Farhan Bashir





Possessing examine this I assumed it had been quite educational. I value you taking some time and energy to place this informative article jointly. I as soon as once again locate myself shelling out approach to considerably time the two reading through and commenting. But so what, it absolutely was nonetheless worthwhile!
What talented idea
I apologise, but, in my opinion, you are not right. I can defend the position.
Please dont apologise , make me correct if I am wrong
The code is giving the following error:
Cannot access protected property Facebook::$user
btw: all posts above (except yours) are left by robots.
HEllo
$temp_pages = $fb->api(‘/’.$fb->user.’/accounts’,'GET’,array(‘access_token’=>$fb->session_key));
In this line replace your $fb->user with the user id and $fb->session_key with your user access token..
This is just a theory but I think it’s pretty sound.
Mulberry Outlet