用于Curl Facebook Linter Url的PHP脚本

时间:2013-01-02 15:25:03

标签: php facebook facebook-graph-api curl

我一直在寻找PHP中的脚本来卷曲facebook linter URL,这样就迫使Facebook再次抓取我的页面来更新我的开放图形数据。

2 个答案:

答案 0 :(得分:4)

根据facebook的文档,您只需使用linter api并传递scrape=true参数即可:

curl -X POST \
    -F "id={object-url OR object-id}" \
    -F "scrape=true" \
    "https://graph.facebook.com"

或使用php:

 $access_token="APP_ID|APP_SECRET"; //replace with your app details
 $params = array("id"=>'/*YOU PAGE URL*/',"scrape"=>"true","access_token"=>$access_token);
 $ch = curl_init("https://graph.facebook.com");
 curl_setopt_array($ch, array(
      CURLOPT_RETURNTRANSFER=>true,
      CURLOPT_SSL_VERIFYHOST=>false,
      CURLOPT_SSL_VERIFYPEER=>false,
      CURLOPT_POST=>true,
      CURLOPT_POSTFIELDS=>$params
 ));
 $result = curl_exec($ch);

here

所述

答案 1 :(得分:0)

这是我找到的脚本,并在stackoverflow的帮助下纠正了一下!

$url = "http://developers.facebook.com/tools/debug/og/object?q=http://www.example.com";
$useragent = "Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.10.229 Version/11.60";

if ( $ch = curl_init( $url ) )
{
    curl_setopt( $ch , CURLOPT_HEADER , 0 );
    curl_setopt( $ch , CURLOPT_RETURNTRANSFER , true );
    curl_setopt( $ch , CURLOPT_USERAGENT , $useragent );
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    $str_response = curl_exec( $ch );

    if( curl_errno( $ch ) != 0 )
    {
        $message = 'Girl of the day - cURL exec error: ' . $ch;

        error_log( $message );
    }

    curl_close( $ch );
}
else
{
    $message = 'Girl of the day - cURL init with url: ' . $url . ' failed';

    error_log( $message );
}