两条腿OAuth Yahoo PHP示例

时间:2013-11-02 11:39:49

标签: php oauth yahoo-api two-legged

我尝试为Yahoo制作私有API请求。我使用下面的代码,但它不起作用。它总是返回消息'invalid sig'。 你能帮助我使用一个有效的双腿OAuth Yahoo PHP示例吗?

非常感谢。

<?php // a super-stripped down 2-leg oauth server/client example

//http://oauth.net/code/
//http://oauth.googlecode.com/svn/code/php/OAuth.php
require 'oauth.php';

$key = 'key';
$secret = 'secret';
$consumer = new OAuthConsumer($key, $secret);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();

if ($_GET['server']) {
    $method = $_SERVER['REQUEST_METHOD'];
    $uri = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    $sig = $_GET['oauth_signature'];
    $req = new OAuthRequest($method, $uri);
    // token is null because we're doing 2-leg
    $valid = $sig_method->check_signature($req, $consumer, null, $sig);
    if (!$valid) {
        die('invalid sig');
    }
    echo 'orale!';
}
else {
    // call this file
    $api_endpoint = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
    // handle request in 'server' block above
    $parameters = array(
            'server' => 'true');

    // use oauth lib to sign request
    $req = OAuthRequest::from_consumer_and_token($consumer, null, "GET", $api_endpoint, $parameters);
    $sig_method = new OAuthSignatureMethod_HMAC_SHA1();
    $req->sign_request($sig_method, $consumer, null); // note: double entry of token

    // get data using signed url
    $ch = curl_init($req->to_url());
    curl_exec($ch);
    curl_close($ch);
}

1 个答案:

答案 0 :(得分:0)

您是否根据雅虎规范here生成签名? 或者您可以使用here所述的纯文本签名。