PHP code example of oauth-io / oauth

1. Go to this page and download the library: Download oauth-io/oauth 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/ */

    

oauth-io / oauth example snippets




Auth_io\OAuth;

//



use OAuth_io\OAuth;

//


$oauth = new OAuth();
$oauth->initialize('your_key', 'your_secret');
//


$_SESSION['some_subarray_in_the_session'] = array();
$myarray = $_SESSION['some_subarray_in_the_session'];

$oauth = new OAuth($myarray);
//


$oauth = new OAuth(null, false);
//

$oauth->redirect('the_provider', '/callback/url');

$request_object = $oauth->auth('the_provider', array(
    'redirect' => true
));

$request_object = $oauth->auth('the_provider');

$credentials = $request_object->getCredentials();
// Here save the $credentials array for later use

$request_object = $oauth->auth('the_provider', array(
    'credentials' => $credentials
));


$response_GET = $request_object->get('https://theprovider.com/api/endpoint');

$response_POST = $request_object->post('https://theprovider.com/api/endpoint', array('some' => 'data'));
$response_PUT = $request_object->put('https://theprovider.com/api/endpoint', array('some' => 'data'));
$response_DELETE = $request_object->del('https://theprovider.com/api/endpoint');
$response_PATCH = $request_object->patch('https://theprovider.com/api/endpoint', array('some' => 'data'));
//


$facebook_requester = $oauth->auth('facebook', array(
    'redirect' => true
));

$result = $facebook_requester->me(array('firstname', 'lastname', 'email'));

// you'll have $result["firstname"], $result["lastname"] and $result["email"] set with the user's facebook information.
//

$request_object = $oauth->auth('the_provider', array(
    'credentials' => $credentials,
    'force_refresh' => true
));

$refreshed_credentials = $oauth->refreshCredentials($old_credentials);