<?php

$a = array();
$a['oauth_token'] = null;
$a['oauth_token_secret'] = null;
$a['authentification_url'] = null;
$oauth_client = new Oauth("key", "secret");
$oauth_client->enableDebug();
try {
    $info = $oauth_client->getRequestToken("http://192.168.187.132/oauth/request_token?oauth_callback=http://192.168.187.132/client/callback.php");
    // Merge in the dummy values, to surpress missing index warnings.
    $info = array_merge($a, $info);
    echo "<h1>We have a request token !</h1>";
    echo "<strong>Request token</strong> : " . $info['oauth_token'] . "<br />";
    echo "<strong>Request token secret</strong> : " . $info['oauth_token_secret'] . "<br />";
    echo "to authenticate go <a href=\"" . $info['authentification_url'] . "?oauth_token=" . $info['oauth_token'] . "\">here</a>";
} catch (OAuthException $E) {
    echo "<pre>" . print_r($E->debugInfo, true) . "</pre>";
}
Exemple #2
0
<?php

@(require_once 'config.inc.php');
$oauth_client = new Oauth(CLIENT_KEY, CLIENT_SECRET);
$oauth_client->enableDebug();
echo "created oauth_client object";
try {
    $info = $oauth_client->getRequestToken("http://localhost/oauth/pages/oauthhandler.php?query=request_token&oauth_callback=http://localhost/oauth/client/callback.php");
    print_r($info);
    echo "<br/><br/><br/><br/>";
    echo "Request token has been obtained";
    echo "Request token:" . $info['oauth_token'];
    echo "Request token secret:" . $info['oauth_token_secret'];
    echo "visit <a href='" . $info['auth_url'] . "&request_token=" . $info['request_token'] . "'>this page</a> to authenticate";
} catch (OAuthException $e) {
    print_r($e);
}
#!/usr/bin/php
<?php 
require "consumer_key.php";
require "api_url_base.php";
require "error.php";
$verbose_debug = true;
try {
    $oauth_client = new Oauth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth_client->enableDebug();
} catch (OAuthException $E) {
    Error("setup exception", $E->getMessage(), null, null, $E->debugInfo);
}
try {
    $info = $oauth_client->getRequestToken("{$api_url_base}/oauth1/request_token/v1", "oob");
    # work around our Pecl getRequestToken->array bug https://bugs.php.net/bug.php?id=63572 :
    if (array_key_exists('oauth_token_secret', $info) && array_key_exists('authentication_url', $info) && !array_key_exists('oauth_token', $info)) {
        $urlArray = parse_url($info['authentication_url']);
        $info['authentication_url'] = $urlArray['scheme'] . '://' . $urlArray['host'] . $urlArray['path'];
        parse_str($urlArray['query']);
        $info['oauth_token'] = $oauth_token;
    }
    if (array_key_exists('oauth_token', $info) && array_key_exists('oauth_token_secret', $info) && array_key_exists('authentication_url', $info)) {
        echo "Request token        : " . $info['oauth_token'] . "\n";
        echo "Request token secret : " . $info['oauth_token_secret'] . "\n";
        echo "Next please authenticate yourself at " . $info['authentication_url'] . "?oauth_token=" . $info['oauth_token'] . " and collect the PIN for the next step.\n";
        $oauth_client->setToken($info['oauth_token'], $info['oauth_token_secret']);
    } else {
        Error("getRequestToken", null, $info, $oauth_client->getLastResponseInfo(), null);
    }
} catch (OAuthException $E) {
    Error("getRequestToken", $E->getMessage(), null, $oauth_client->getLastResponseInfo(), $E->debugInfo);