Created
June 30, 2017 03:30
-
-
Save tiger154/048cac3cb8680be14d791580b585e63e to your computer and use it in GitHub Desktop.
Facebook (public)event crawl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Here is short description each property and information | |
* - To parse url it use 'Embed\Http' from https://github.com/oscarotero/Embed/ | |
* | |
* public $targetUrl: You can change to test | |
* private $endPoint: 'https://graph.facebook.com/' => It's shouldn't be changed | |
* private $facebooKey: XXXXXXXXXX => You must set proper facebookKey | |
* public $fields: You can change it to choose return data you want | |
* - cover field has image data: cover->source | |
* - Required field should be: name, description, cover | |
* | |
*/ | |
$targetUrl = 'https://www.facebook.com/events/1822069678114212/'; // you can change this url | |
$endPoint = 'https://graph.facebook.com/'; | |
$facebooKey = 'XXXXXXXXXX'; | |
$fields = 'description,timezone,start_time,end_time,name,owner,privacy,id,cover'; | |
// 1. Extract URL information | |
$url = Url::create($targetUrl); // Embed\Http | |
// 2. Check if it's Facebook event | |
if ($url->getHost() == 'www.facebook.com' | |
&& $url->getSlicePath(0,1)[0] == 'events' | |
&& is_numeric($url->getSlicePath(1,1)[0]) | |
) { | |
// Get event data | |
$facebook_event_id = $url->getSlicePath(1,1)[0]; // set | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $endPoint.$facebook_event_id.'?access_token='.$facebooKey.'&fields='.$fields); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$r = curl_exec($ch); | |
// return json | |
var_dump(json_decode($r)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment