djchen / oauth1-php
A simple and easy to use OAuth1 library for PHP
Installs: 17 660
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2022-02-01 12:35:37 UTC
README
oauth1-php is a super simple and basic PHP library for making OAuth 1.0 requests.
###Install with Composer
{ "require" : { "djchen/oauth1-php" : "dev-master" }, "autoload": { "psr-0": {"djchen": "src"} } }
###Dependecies Requires PHP 5.3+ and cURL The Unirest library is used to make HTTP requests and is included in the project.
##Usage ###Initializing
$oauth = new OAuth1(array( 'consumerKey' => 'oauth_consumer_key', 'consumerSecret' => 'oauth_consumer_secret', 'token' => 'oauth_token', // optional 'tokenSecret' => 'oauth_token_secret', // optional 'requestTokenUrl' => 'request_token_url', 'accessTokenUrl' => 'access_token_url', ));
###Getting a request token
$result = $oauth->requestToken('callback_url');
$result is an array with the response params => values
###Getting an access token
$result = $oauth->accessToken('oauth_token', 'oauth_token_secret', 'oauth_verifier');
$result is an array with the response params => values
###Making API calls
$response = $oauth->get($url, $params = array(), $httpHeaders = array(), $oauthParams = array()); $response = $oauth->post($url, $body = null, $httpHeaders = array(), $oauthParams = array()); $response = $oauth->put($url, $body = null, $httpHeaders = array(), $oauthParams = array()); $response = $oauth->delete($url, $body = null, $httpHeaders = array(), $oauthParams = array());
The $response is an object with these fields
$response->code; // HTTP Response Status Code $response->headers; // HTTP Response Headers $response->body; // Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays. $response->raw_body; // Original un-parsed response body
Debug mode can be turned on via $oauth->setDebug(true)
. This will log both request headers and response headers and body.