0

How to add new client to OAuth and setup

First you should create a new client and put some information about the client and his application.

1

 

2

Now back again to the client that you have created now you will find the client keys generated.

3

Now you should send to the client the next information:

  1. The keys already generated
  2. 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:

http://smartiolabs.com/demo/oauth.zip

smartiolabs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.