Skip to content

Instantly share code, notes, and snippets.

@imanilchaudhari
Created November 21, 2016 09:37
Show Gist options
  • Save imanilchaudhari/01e8b548dc2716d9d9c9bde8db4abb49 to your computer and use it in GitHub Desktop.
Save imanilchaudhari/01e8b548dc2716d9d9c9bde8db4abb49 to your computer and use it in GitHub Desktop.
<?php
namespace backend\components;
class FacebookDebugger
{
/*
* https://developers.facebook.com/docs/opengraph/using-objects
*
* Updating Objects
*
* When an action is published, or a Like button pointing to the object clicked,
* Facebook will 'scrape' the HTML page of the object and read the meta tags.
* The object scrape also occurs when:
*
* - Every 7 days after the first scrape
*
* - The object URL is input in the Object Debugger
* http://developers.facebook.com/tools/debug
*
* - When an app triggers a scrape using an API endpoint
* This Graph API endpoint is simply a call to:
*
* POST /?id={object-instance-id or object-url}&scrape=true
*/
/* USAGES
* ======
* $fb = new FacebookDebugger();
* $fb->reload('http://example.com/');
* $fb->reload('http://example.com/foo');
* $fb->reload('http://example.com/bar');
*/
public function reload($url)
{
$graph = 'https://graph.facebook.com/';
$post = 'id='.urlencode($url).'&scrape=true';
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;
}
}
@BlueprintBQ
Copy link

How do i make use of this, sorry kinda new to this

@imanilchaudhari
Copy link
Author

@BlueprintBQ just create an object of FacebookDebugger and pass your url to reload function. you can also view uses details at here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment