PHP code example of socialiteproviders / threads
1. Go to this page and download the library: Download socialiteproviders/threads library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
socialiteproviders / threads example snippets
'threads' => [
'client_id' => env('THREADS_CLIENT_ID'),
'client_secret' => env('THREADS_CLIENT_SECRET'),
'redirect' => env('THREADS_REDIRECT_URI')
],
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
$event->extendSocialite('threads', \SocialiteProviders\Threads\Provider::class);
});
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\Threads\ThreadsExtendSocialite::class.'@handle',
],
];
return Socialite::driver('threads')->redirect();
public function exchangeAccessToken(string $accessToken): string
{
$response = Http::post('https://graph.threads.net/access_token', [
RequestOptions::HEADERS => [
'Content-Type' => 'application/json'
],
RequestOptions::FORM_PARAMS => [
'access_token' => $accessToken,
'client_secret' => config('threads.client_secret'),
'grant_type' => 'th_exchange_token',
],
]);
$response = json_decode((string) $response->getBody(), true);
return $response['access_token'];
}
public function refreshAccessToken(string $accessToken): string
{
$response = Http::post('https://graph.threads.net/refresh_access_token', [
RequestOptions::HEADERS => [
'Content-Type' => 'application/json'
],
RequestOptions::FORM_PARAMS => [
'access_token' => $accessToken,
'grant_type' => 'th_refresh_token',
],
]);
$response = json_decode((string) $response->getBody(), true);
return $response['access_token'];
}