Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (23)

View Page History
* Zend_Oauth_Consumer
* Zend_Oauth_Server
* Zend_Oauth_Request_RequestToken Zend_Oauth_Http
* Zend_Oauth_Request_AccessToken Zend_Oauth_Http_RequestToken
* Zend_Oauth_Response_RequestToken Zend_Oauth_Http_AccessToken
* Zend_Oauth_Response_AccessToken Zend_Oauth_Http_UserAuthorisation
* Zend_Oauth_Http_Utility
* Zend_Oauth_Client
* Zend_Oauth_Token
* Zend_Oauth_Token_Request
* Zend_Oauth_Token_Access
* Zend_Oauth_Token_Access
* Zend_Oauth_Exception


||UC-01||
A start to finish example using the Ma.gnolia API:

Retrieve a Request Token on foot of a user request requiring a user's offsite resource from another web service:

{code}
<?php
session_start();

require_once 'Zend/Oauth/Consumer.php';

$options = array(
'signatureMethod' => 'RSA-SHA1',
'requestMethod' => 'POST',
'requestScheme' => 'HEADER', Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'signatureMethod' => 'HMAC-SHA1',
'localUrl' => 'http://example.com/edit_entry', 'http://your/path/to/this/file.php',
'requestTokenUrl' => 'https://photos.example.net/request_token', 'http://ma.gnolia.com/oauth/get_request_token',
'userAuthorisationUrl' => 'http://ma.gnolia.com/oauth/authorize',
'accessTokenUrl' => 'https://photos.example.net/access_token', 'http://ma.gnolia.com/oauth/get_access_token',
'userAuthorisationUrl' => 'http://photos.example.net/authorize'
'consumerKey' => 'YOUR_CONSUMER_KEY',
'consumerSecret' => 'YOUR_CONSUMER_KEY_SECRET'
);

$consumer = new Zend_Oauth_Consumer('dpf43f3p2l4k3l03', 'kd94hf93k423kf44', $options);
$requestToken = $consumer->getRequestToken(); // instance of Zend_Oauth_Token_Request

if (!isset($_SESSION['ACCESS_TOKEN'])) {
if (!empty($_GET)) {
$token = $consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN']));
$_SESSION['ACCESS_TOKEN'] = serialize($token);
} else {
$token = $consumer->getRequestToken();
$_SESSION['REQUEST_TOKEN'] = serialize($token);
$consumer->redirect();
}
} else {
$token = unserialize($_SESSION['ACCESS_TOKEN']);
$_SESSION['ACCESS_TOKEN'] = null; // forces reset of access token on all example runs ;)
}

// the client is a Zend_Http_Client subclass with built-in OAuth request handling
$client = $token->getHttpClient($options);
$client->setUri('http://ma.gnolia.com/api/rest/2/bookmarks_count'); // we're counting!
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost('group','oauth'); // bookmarks for the OAuth Group

$response = $client->request();
header('Content-Type: ' . $response->getHeader('Content-Type'));
echo $response->getBody();

// Retrieved XML will be similar to:

// <?xml version="1.0" encoding="utf-8" ?>
// <response status="ok" version="">
// <count>138</count>
// </response>
{code}
{zone-data}