你好
我的代码有点问题:
如果我使用,它会起作用
FB.api('https://graph.facebook.com/','post', {
id: 'http://example.fr/',
scrape: true,
access_token:'xxxxx|xxxxxx'
}, function(response) {
console.log('rescrape!',response);
});
对于安全令牌,我想使用serveur端,如果我使用以下代码(使用ajax发送url):
class FacebookDebugger {
public function reload($url)
{
$token = 'xxxxxxxxxxxxxxx|xxxxxxxxxxx';
$graph = 'https://graph.facebook.com/';
$post = 'id='.urlencode($url).'&scrape=true&access_token='.$token;
return $this->send_post($graph, $post);
}
private function send_post($url, $post)
{
$r = curl_init();
curl_setopt($r, CURLOPT_URL, $url);
curl_setopt($r, CURLOPT_POST, 1);
curl_setopt($r, CURLOPT_POSTFIELDS, $post);
curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($r, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($r);
curl_close($r);
return $data;
}
}
$fb = new FacebookDebugger();
$fb = $fb->reload($url)
它不起作用。响应ajax
$fb = new FacebookDebugger();
$fbrepons = $fb->reload($url)
echo var_dump($fbrepons);
我有"布尔false"。
一个主意?
感谢您的帮助
在这里找到好的代码
有没有API可以迫使Facebook再次抓取页面?
//Provide a URL in $url to empty the OG cache
function clear_open_graph_cache($url) {
$vars = array('id' => $url, 'scrape' => 'true');
$body = http_build_query($vars);
$fp = fsockopen('ssl://graph.facebook.com', 443);
fwrite($fp, "POST / HTTP/1.1'r'n");
fwrite($fp, "Host: graph.facebook.com'r'n");
fwrite($fp, "Content-Type: application/x-www-form-urlencoded'r'n");
fwrite($fp, "Content-Length: ".strlen($body)."'r'n");
fwrite($fp, "Connection: close'r'n");
fwrite($fp, "'r'n");
fwrite($fp, $body);
fclose($fp);
}
有一个如何生成Oauth令牌的指南。然后,您必须在curl请求中附加附加头。
private function send_post($url, $post) {
$r = curl_init();
curl_setopt($r, CURLOPT_URL, $url);
curl_setopt($r, CURLOPT_POST, 1);
curl_setopt($r, CURLOPT_POSTFIELDS, $post);
curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($r, CURLOPT_CONNECTTIMEOUT, 5);
$auth_header = 'Oauth ' . {YOUR OAUTH TOKEN};
curl_setopt($r, CURLOPT_HTTPHEADER, array($auth_header));
$data = curl_exec($r);
curl_close($r);
return $data;
}