Suppose i have a facebook page link http://facebook.com开发者_C百科/page_name
and i am not the admin of the page. Is it possible to find out the facebook id, profile pics of the page and fan count?
Thanks!
FB id and some informations: yes. See Graph API docs.
edit: Some code to get id from my app:
$arg = $_REQUEST['arg'];
if ($arg != ''){
$arg = str_replace(
array('http://','www.','facebook.com/','/'),
'',
$arg
);
$elseID = file_get_contents('https://graph.facebook.com/?ids='.$arg.'&fields=id');
$elseID = json_decode($elseID,true);
$elseID = $elseID[$arg]['id'];
}
Typically you can do http://graph.facebook.com/{page_name} and receive the appropriate results. For example, Pepsi is at http://www.facebook.com/pepsi and you can see the graph API results at https://graph.facebook.com/pepsi.
You can use Facebook SDK for PHP https://github.com/facebook/php-graph-sdk
Below my solution
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
$pageUrl = 'some_url';
FacebookSession::setDefaultApplication('facebookAppId','facebookAppSecret');
//getting session
$Session = FacebookSession::newAppSession();
try
{
//validating if session is correct
$Session->validate();
//sending request
$Request = new FacebookRequest($Session, 'GET', '/',
array (
'id' => $pageUrl,
)
);
$Response = $Request->execute();
//getting UserGraph object
$UserObject = $Response->getGraphObject(GraphUser::className());
//return page id
return $UserObject->GetId();
}
catch (FacebookRequestException $ex)
{}
catch (Exception $ex)
{}
精彩评论