Last active
November 29, 2019 05:00
-
-
Save joey-barbier/6c9dd041a8d4edb5c55b8d5ff9da6639 to your computer and use it in GitHub Desktop.
Facebook generates a token that never expires - PHP
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
public function getNeverExpireToken($token) | |
{ | |
$clientId = FB_APP_ID; | |
$clientSecret = FB_APP_SECRET; | |
//long lived token : | |
$apiUrl = "https://graph.facebook.com/v3.0"; | |
$apiToken = "$apiUrl/oauth/access_token?grant_type=fb_exchange_token&client_id=$clientId&client_secret=$clientSecret&fb_exchange_token=$token"; | |
$response = file_get_contents($apiToken); | |
$longLiveToken = json_decode($response)->access_token; | |
// user id : | |
$apiUser = "$apiUrl/me?access_token=$longLiveToken"; | |
$responseUser = file_get_contents($apiUser); | |
$idUser = json_decode($responseUser)->id; | |
// never expires token : | |
$apiPermaToken = "$apiUrl/$idUser/accounts?access_token=$longLiveToken&fields=access_token,name,id,instagram_business_account"; | |
$responsePermaToken = file_get_contents($apiPermaToken); | |
$data = json_decode($responsePermaToken)->data; | |
// get tokens : | |
foreach ($data as $el) { | |
$name = $el->name; | |
$id = $el->id; | |
$token = ['access_token' => $el->access_token]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment