Created
December 14, 2022 08:08
-
-
Save mbrughi/0bbbc060520029a809eda62cae51a97c to your computer and use it in GitHub Desktop.
Facebook API test
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
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Access-Control-Allow-Headers: *"); | |
// Variabili | |
$vars = array ( | |
ip => $_SERVER['REMOTE_ADDR'], | |
agent => $_SERVER['HTTP_USER_AGENT'], | |
current_page => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", | |
fbp => $_COOKIE[_fbp], | |
timestamp => date_create()->getTimestamp() | |
); | |
bdump($vars); | |
// API Url | |
$url = 'https://graph.facebook.com/v9.0/315778062424477/events?access_token=EAAMd6dqmADgBADrCBGInyn2Tc1l148tJc8axEV4N4ydLcRYou24aRlZAaplAYU6gZApTCGYcePm13mnrKySPI7k25hjr7KRwW7LzC7lOyZCwXX9SPoVxXPHOWXnpyeOr29r2GSsei6V79ZBCO6cbEkZCmsHZCutPZAFlVA9dcXZB8TWK608tEoAxGVyZBzUVROroZD'; | |
// Data. | |
$data = array ( | |
'data' => | |
array ( | |
0 => | |
array ( | |
'event_name' => 'ViewContent', | |
'event_source_url' => $vars[current_page], | |
'event_time' => $vars[timestamp], | |
'action_source' => 'website', | |
'user_data' => | |
array ( | |
'client_ip_address' => $vars[ip], | |
'client_user_agent' => $vars[agent], | |
'fbp' => $vars[fbp], | |
), | |
'custom_data' => | |
array ( | |
'PHP' => 'HELL YEAH!!' | |
), | |
) | |
), | |
'test_event_code' => 'TEST54923', | |
); | |
// [DEV] Output di controllo | |
bdump($data); | |
// Encode Array => JSON | |
$payload = json_encode($data); | |
// Inizializza chiamata cURL. | |
$ch = curl_init($url); | |
// Imposta payload | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
// Imposta JSON | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); | |
// Ritorna la risposta in formato stringa | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// Registra risultato | |
$result = curl_exec($ch); | |
// Chiudi chiamata cURL | |
curl_close($ch); | |
// [DEV] Output resultato | |
// echo "$result"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment