1. Go to this page and download the library: Download webiik/oauth1client 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/ */
webiik / oauth1client example snippets
// Twitter Example
// Prepare dependencies
$chc = new \Webiik\CurlHttpClient\CurlHttpClient();
$token = new \Webiik\Token\Token();
// Instantiate OAuth1 client
$oAuth1Client = new \Webiik\OAuth1Client\OAuth1Client($chc, $token);
// Set your callback URL
// OAuth1 server redirects users to this URL, after user verification
$oAuth1Client->setCallbackUrl('https://127.0.0.1/webiik/');
// Set OAuth1 server endpoints
$oAuth1Client->setAuthorizeUrl('https://api.twitter.com/oauth/authenticate');
$oAuth1Client->setRequestTokenUrl('https://api.twitter.com/oauth/request_token');
$oAuth1Client->setAccessTokenUrl('https://api.twitter.com/oauth/access_token');
// Set OAuth1 server access credentials (create yours at https://developer.twitter.com/en/apps)
$oAuth1Client->setConsumerKey('your-api-key');
$oAuth1Client->setConsumerSecret('your-api-secret');
// Make API calls...
// Notice: It's a good idea to separate below steps to individual routes.
if (!isset($_GET['oauth_verifier'])) {
// 1. Prepare Twitter login link
echo '<a href="' . $oAuth1Client->getAuthorizeUrl() . '" target="_blank">Authorize with Twitter</a><br/>';
}
if (isset($_GET['oauth_verifier'])) {
// 2. Verify oauth_token
$accessToken = $oAuth1Client->getAccessToken();
}
if (isset($accessToken, $accessToken['oauth_token'], $accessToken['oauth_token_sercret'])) {
// 3. oauth_token is valid, user is authorized by Twitter
// Access protected resources...
$urlParameters = [
'skip_status' => 'true',
];
$res = $oAuth1Client->get('https://api.twitter.com/1.1/account/verify_credentials.json', $accessToken['oauth_token'], $accessToken['oauth_token_secret'], $urlParameters);
header('Content-Type: application/json');
echo $res;
}