Fel*_*ahm 44 caching facebook-sharer facebook-like facebook-graph-api facebook-opengraph
我知道您可以通过在Facebook的调试工具上输入URL来强制更新页面缓存,同时以该应用程序/页面的管理员身份登录:https: //developers.facebook.com/tools/debug
但我需要的是一种方法,只要我们的销售部门的某个人更新我们其中一个页面的主图像,就可以从我们的内部应用程序自动调用API端点或其他内容.要求数千名销售人员以管理员身份登录并在更新我们项目的描述或图像时手动更新页面缓存,这不是一种选择.
我们不能等待24小时让Facebook更新其缓存,因为我们每当我们改变它的时候没有看到更改出现时,我们每天都会得到客户的投诉.
Igy*_*Igy 76
页面元数据不是那种应该经常更改的东西,但您可以通过转到Facebook的调试工具并输入要刮的URL 来手动清除缓存
还有一个用于执行此操作的API,适用于任何OG对象:
curl -X POST \
-F "id={object-url OR object-id}" \
-F "scrape=true" \
-F "access_token={your access token}" \
"https://graph.facebook.com"
Run Code Online (Sandbox Code Playgroud)
现在需要access_token.这可以是app或page access_token; 不需要用户身份验证.
Sha*_*onn 15
如果你想在没有等待回复的情况下在PHP中执行此操作,则以下函数将执行此操作:
//Provide a URL in $url to empty the OG cache
function clear_open_graph_cache($url, $token) {
$vars = array('id' => $url, 'scrape' => 'true', 'access_token' => $token);
$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);
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用javascript sdk,那么您想要使用的版本是
FB.api('https://graph.facebook.com/', 'post', {
id: [your-updated-or-new-link],
scrape: true
}, function(response) {
//console.log('rescrape!',response);
});
Run Code Online (Sandbox Code Playgroud)
我碰巧喜欢promises,所以使用jQuery Deferreds的替代版本可能是
function scrapeLink(url){
var masterdfd = $.Deferred();
FB.api('https://graph.facebook.com/', 'post', {
id: [your-updated-or-new-link],
scrape: true
}, function(response) {
if(!response || response.error){
masterdfd.reject(response);
}else{
masterdfd.resolve(response);
}
});
return masterdfd;
}
Run Code Online (Sandbox Code Playgroud)
然后:
scrapeLink([SOME-URL]).done(function(){
//now the link should be scraped/rescraped and ready to use
});
Run Code Online (Sandbox Code Playgroud)
请注意,刮刀可能需要不同的时间才能完成,因此不能保证它很快.我也不知道Facebook对这种方法的重复或自动使用的看法,因此使用它可能是明智和保守的.
小智 5
这是一个简单的ajax实现.把它放在你想让facebook立即刮掉的任何页面上;
var url= "your url here";
$.ajax({
type: 'POST',
url: 'https://graph.facebook.com?id='+url+'&scrape=true',
success: function(data){
console.log(data);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42253 次 |
| 最近记录: |