Posts

Showing posts with the label Facebook Graph API

HOWTO in PHP: Retrieve a list of Facebook Pages you are the Administrator of using Graph API

Image
Here's the code. I am assuming here that you have already logged in as a valid Facebook user with the "manage_pages" scope permission. <?php require_once("fbphpsdk/facebook.php"); $config = array(); $config['appId'] = 'YOUR_APP_ID'; $config['secret'] = 'YOUR_APP_SECRET'; $config['fileUpload'] = false; // optional $facebook = new Facebook($config); $uid = $facebook->getUser(); $accesstoken = $facebook->getAccessToken(); $params = array('access_token' => $accesstoken); if ($uid) { try { $userprofile = $facebook->api('/me','GET'); echo "Name: " . $userprofile['name']; $accounts = $facebook->api('/me/accounts', 'GET', $params); foreach($accounts['data'] as $account) { echo "<hr/>" . $account['name'] . " " . $account['id'] . "<br/>...

How to get the Page ID of a Facebook Page from its username

Image
It is very easy Just type this in the addressbar of your browser and press enter. http://graph.facebook.com/<pageurl>/ E.g. when I type the following URL of my own Facebook Page, I yield the results as in Figure 1 below. http://graph.facebook.com/dorathetechplorer/ Hence, the Page ID of my page would be "157472464323620". Figure 1: Output from typing "http://graph.facebook.com/dorathetechplorer"

How to retrieve posts from Facebook Page using Facebook Graph API and php

Here's a simple php script that will split out the latest 100 posts from a given Facebook Page. Note that you will need to modify the code at lines 1 and 2 by: generating your own access token either using the oAuth dialog or via Facebook Graph API Explorer . specifying the page id of the target Facebook Page Have fun trying it out! :) <? $access_token="&access_token=YOUR_ACCESS_TOKEN_HERE"; $pageid="THE_PAGE_ID"; $graph_query_url="https://graph.facebook.com/" . $pageid . "?fields=posts.limit(100)" . $access_token; $graph_query_result = @file_get_contents($graph_query_url); $graph_query_obj = json_decode($graph_query_result,true); foreach($graph_query_obj[posts][data] as $p) { echo $p[from][name] . "<br/>"; if ($p[story]) echo $p[story] . "<br/>"; if ($p[message]) echo $p[message] . "<br/>"; if ($p[picture]) echo "<img src='" . $p[p...