你好
我的代码有一些问题:
如果我使用它,它就会起作用:
FB.api('https://graph.facebook.com/','post', {
id: 'http://example.fr/',
scrape: true,
access_token:'xxxxx|xxxxxx'
}, function(response) {
console.log('rescrape!',response);
});
对于安全令牌,如果我使用以下代码(使用ajax发送url ),我希望使用serveur端:
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);
我有“布尔值为假”。
一个想法?
谢谢你的帮助
发布于 2016-05-01 04:34:20
在这里找到好的代码
Is there an API to force Facebook to scrape a page again?
//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);
}
发布于 2017-02-14 03:57:29
There is a guide如何生成Oauth token.Then你必须附加到你的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;
}
https://stackoverflow.com/questions/36957760
复制相似问题