Skip to content

Instantly share code, notes, and snippets.

@SunboX
Created May 8, 2010 17:33
Show Gist options
  • Select an option

  • Save SunboX/394670 to your computer and use it in GitHub Desktop.

Select an option

Save SunboX/394670 to your computer and use it in GitHub Desktop.
<?php
session_start();
require_once('lib/oauth/OAuthStore.php');
require_once('lib/oauth/OAuthRequester.php');
$options = array(
'server' => 'localhost',
'username' => 'xxxxxx',
'password' => 'apitest',
'database' => 'xxxxxxx'
);
$store = OAuthStore::instance('MySQL', $options);
// Request parameters are oauth_token, consumer_key and usr_id.
$consumer_key = $_GET['consumer_key'];
$oauth_token = $_GET['oauth_token'];
$user_id = (int)$_GET['usr_id'];
try
{
OAuthRequester::requestAccessToken($consumer_key, $oauth_token, $user_id);
}
catch (OAuthException $e)
{
// Something wrong with the oauth_token.
// Could be:
// 1. Was already ok
// 2. We were not authorized
}
// The request uri being called.
$request_uri = 'http://www.xyz.com/xyz/new.xml';
// Parameters, appended to the request depending on the request method.
// Will become the POST body or the GET query string.
$params = array(
'method' => 'ping'
);
// Obtain a request object for the request we want to make
$req = new OAuthRequester($request_uri, 'POST', $params);
// Sign the request, perform a curl request and return the results, throws OAuthException exception on an error
$result = $req->doRequest($user_id);
// $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment