<commit_before>#OAuth 1.0 Consumer for PHP
   

##Usage


###Obtaining and authenticating a request token

```php
<?php
/**
 * authenticate.php
 */
require_once './vendor/autoload.php';

use danperron\OAuth\OAuthConsumer;
use danperron\OAuth\OAuthException;

session_start();

$consumerKey = '{YOUR_CONSUMER_KEY}';
$consumerSecret = '{YOUR_CONSUMER_SECRET}';

//create a new OAuthConsumer
$oauthConsumer = new OAuthConsumer($consumerKey, $consumerSecret);

$oauthConsumer->setRequestTokenUrl('https://api.twitter.com/oauth/request_token');
$oauthConsumer->setAccessTokenUrl('https://api.twitter.com/oauth/access_token');
$oauthConsumer->setAuthorizeUrl('https://api.twitter.com/oauth/authorize');
$oauthConsumer->setCallbackUrl('{URL to callback.php}');

try {
    //Fetch request token
    $requestToken = $oauthConsumer->fetchRequestToken();
    
    //Add the consumer and the request token to the session
    $_SESSION['oauthConsumer'] = $oauthConsumer;
    $_SESSION['requestToken'] = $requestToken;
    
    //Authorize request token will perform a redirect
    $oauthConsumer->authorizeToken($requestToken);
    
} catch (OAuthException $e) {
    echo $e->getTraceAsString();
}
```

###Authenticating a request token

```php
<?php
/**
 * callback.php
 */
require_once './vendor/autoload.php';

use danperron\OAuth\OAuthConsumer;
use danperron\OAuth\OAuthException;
use danperron\OAuth\OAuthToken;

session_start();

//Retrieve OAuthConsumer from session
$oauthConsumer = $_SESSION['oauthConsumer'];
/* @var $oauthConsumer OAuthConsumer */

//Retrieve request token from session
$requestToken = $_SESSION['requestToken'];
/* @var $requestToken OAuthToken */
try {<commit_msg>Add Installation instructions to readme<commit_after>#OAuth 1.0 Consumer for PHP
   

##Installation

Simply add the following requires to your composer.json and run **php composer.phar update**.

```json
{
    "minimum-stability":"dev",
    "require": {
        "danperron/oauthconsumer":"*"
    }
}
```

##Usage


###Obtaining and authenticating a request token

```php
<?php
/**
 * authenticate.php
 */
require_once './vendor/autoload.php';

use danperron\OAuth\OAuthConsumer;
use danperron\OAuth\OAuthException;

session_start();

$consumerKey = '{YOUR_CONSUMER_KEY}';
$consumerSecret = '{YOUR_CONSUMER_SECRET}';

//create a new OAuthConsumer
$oauthConsumer = new OAuthConsumer($consumerKey, $consumerSecret);

$oauthConsumer->setRequestTokenUrl('https://api.twitter.com/oauth/request_token');
$oauthConsumer->setAccessTokenUrl('https://api.twitter.com/oauth/access_token');
$oauthConsumer->setAuthorizeUrl('https://api.twitter.com/oauth/authorize');
$oauthConsumer->setCallbackUrl('{URL to callback.php}');

try {
    //Fetch request token
    $requestToken = $oauthConsumer->fetchRequestToken();
    
    //Add the consumer and the request token to the session
    $_SESSION['oauthConsumer'] = $oauthConsumer;
    $_SESSION['requestToken'] = $requestToken;
    
    //Authorize request token will perform a redirect
    $oauthConsumer->authorizeToken($requestToken);
    
} catch (OAuthException $e) {
    echo $e->getTraceAsString();
}
```

###Authenticating a request token and making a authorized call.

```php
<?php
/**
 * callback.php
 */
require_once './vendor/autoload.php';

use danperron\OAuth\OAuthConsumer;
use danperron\OAuth\OAuthException;
use danperron\OAuth\OAuthToken;

session_start();

//Retrieve OAuthConsumer from session
$oauthConsumer = $_SESSION['oauthConsumer'];
/* @var $oauthConsumer OAuthConsumer */

//Retrieve request token from session
$requestToken = $_SESSION['requestToken'];
/* @var $requestToken OAuthToken */
try {
{'fraction_non_alphanumeric': 0.14101154480483782, 'fraction_numerical': 0.0010995052226498076, 'mean_word_length': 5.04485049833887, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '844814', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1145, 'n_words': 245}