【发布时间】:2017-02-18 01:35:49
【问题描述】:
假设我有一个 Facebook 页面链接 http://facebook.com/page_name,但我不是该页面的管理员。能查到facebook id、页面头像和粉丝数吗?
谢谢!
【问题讨论】:
标签: php facebook facebook-page
假设我有一个 Facebook 页面链接 http://facebook.com/page_name,但我不是该页面的管理员。能查到facebook id、页面头像和粉丝数吗?
谢谢!
【问题讨论】:
标签: php facebook facebook-page
FB id 和一些信息:是的。见Graph API docs。
编辑: 从我的应用中获取 id 的一些代码:
$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'];
}
【讨论】:
通常您可以执行http://graph.facebook.com/{page_name} 并获得适当的结果。例如,Pepsi 在http://www.facebook.com/pepsi,您可以在https://graph.facebook.com/pepsi 看到图形API 结果。
【讨论】:
$info = json_decode(file_get_contents("http://www.facebook.com/pepsi")); 有效)。
您可以使用 Facebook SDK for PHP https://github.com/facebook/php-graph-sdk
在我的解决方案之下
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)
{}
【讨论】: