我正在寻找单个小任务的解决方案。我想知道如何使用PHP获取Facebook粉丝页面,组和用户个人资料ID的ID。
我已经尝试了很多事情,但不幸的是我无法找到解决方案。
例如,如何从下面的链接获取ID
粉丝页面 = https://facebook.com/pepsi组 = https://www.facebook.com/groups/TeespringNews/配置文件相同
<?php
$id= $_GET['group-id'];
?>
谢谢
这是图形 api 2.8 的测试和首先通过图形 API 登录获取应用访问令牌
初始化 Facebook PHP SDK v5。
require( __DIR__.'/path-to-sdk/autoload.php' );
`$fb = new Facebook'Facebook([
'app_id' => 'xxxxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.8',
]);`
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook'Exceptions'FacebookSDKException $e) {
//There was an error communicating with Graph
echo $e->getMessage();
exit;
}
if (isset($accessToken)) {
// User authenticated your app!
$_SESSION['facebook_access_token'] = (string) $accessToken;
echo 'Successfull!';
exit;
} elseif ($helper->getError()) {
// The user denied the request
var_dump($helper->getError());
exit;
}
$url = 'https://www.facebook.com/testpage/';
if ($url != ''){
$arg = str_replace(
array('http://','https://','www.','facebook.com/','/'),
'',
$url
);
}
$url="https://graph.facebook.com/{$arg}?access_token=".$_SESSION['facebook_access_token'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
$content = curl_exec($ch);
$content = json_decode($content);
var_dump($content);
您需要使用 Graph API 从 Facebook 获取数据,不允许抓取。
例如:
$pageData = file_get_contents('https://graph.facebook.com/pepsi');
虽然,我建议使用 CURL 而不是file_get_contents。而且,每次访问图形 API 时,都应始终创建应用并使用访问令牌。详细信息: https://developers.facebook.com/docs