Created
June 23, 2019 10:56
-
-
Save maythiwat/5eeb0ab7f8595998523e39b6df267b89 to your computer and use it in GitHub Desktop.
Facebook Get Access Token
This file contains hidden or 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 | |
function iCurl($url, $data = false, $header = false) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36'); | |
if($header){ | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
} | |
if($data){ | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
} | |
return curl_exec($ch); | |
} | |
function prettyPrint($str) { | |
return '<pre>'.print_r($str, true).'</pre>'; | |
} | |
/////////////////////////////// | |
function makeSig(&$data) { | |
$sig = ''; | |
foreach ($data as $key => $value) { | |
$sig .= "{$key}={$value}"; | |
} | |
return md5($sig.'62f8ce9f74b12f84c123cc23437a4a32'); | |
} | |
function getToken($user, $pass) { | |
$header = array( | |
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36" | |
); | |
$data = array( | |
"api_key" => "882a8490361da98702bf97a021ddc14d", | |
"credentials_type" => "password", | |
"email" => $user, | |
"format" => "JSON", | |
"generate_machine_id" => "1", | |
"locale" => "en_US", | |
"method" => "auth.login", | |
"password" => $pass, | |
"return_ssl_resources" => "1", | |
"v" => "1.0" | |
); | |
$data['sig'] = makeSig($data); | |
return iCurl('https://api.facebook.com/restserver.php?'.http_build_query($data), false, $header); | |
} | |
function shield($token, $uid, $status) { | |
$header = array( | |
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36", | |
"Authorization: Bearer {$token}" | |
); | |
$data = array( | |
"variables" => json_encode(array( | |
"input" => array( | |
"is_shielded" => "{$status}", | |
"actor_id" => $uid, | |
"client_mutation_id" => "b0316dd6-3fd6-4beb-aed4-bb29c5dc64b0" | |
) | |
)), | |
"doc_id" => "1477043292367183", | |
"access_token" => "{$token}" | |
); | |
return iCurl('https://graph.facebook.com/graphql', $data, $header); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment