0

Hello

i have some trouble with my code :

It's working if i use that :

FB.api('https://graph.facebook.com/','post',  {
    id: 'http://example.fr/',
    scrape: true,
    access_token:'xxxxx|xxxxxx'
}, function(response) {
    console.log('rescrape!',response);

});

For secure token, i want to use serveur side, if i use this code ( with ajax to send 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)

It's not working. In respons ajax

   $fb = new FacebookDebugger();
        $fbrepons = $fb->reload($url)

        echo var_dump($fbrepons);

I have " boolean false".

An idea ?

Thanks you for your help

2 Answers2

0

Good code find here

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);
}
Community
  • 1
  • 1
0

There is a guide how to generate Oauth token.Then you have to append to your curl request addtional headers.

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;
}
Andrzej Piszczek
  • 369
  • 1
  • 13