First you should create a new client and put some information about the client and his application.
Now back again to the client that you have created now you will find the client keys generated.
Now you should send to the client the next information:
- The keys already generated
- Your AUTHORIZATION & TOKEN URI and they are should be like that:
AUTHORIZATION URI => http://yourwordpess.com/api/authorize/
TOKEN URI => http://yourwordpess.com/api/access_token/
With this information the client can connect to your API through this code
<?php
require('OAuth.php');
const CLIENT_ID = 'REPLACE_CLIENT_ID';
const CLIENT_SECRET = 'REPLACE_CLIENT_SECRET';
const REDIRECT_URI = 'http://smartiolabs.com/demo/oauth/callback.php';
const AUTHORIZATION_ENDPOINT = 'http://smartiolabs.com/demo/api/authorize/';
const TOKEN_ENDPOINT = 'http://smartiolabs.com/demo/api/access_token/';
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code'])) {
$auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
header('Location: ' . $auth_url);
}
else {
$params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
$response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
$client->setAccessToken($response['result']['access_token']);
$params = array(
'limit' => 20, //Limit of result data
'range' => 30, //Number of days to calculate and return the most popular posts
'custom_post' => 'video'
);
$response = $client->fetch('http://smartiolabs.com/demo/api/popular_posts/', $params, 'POST');
echo json_encode($response['result']);
}
?>
Download OAuth library files from this link: