2013-11-02 4 views
0

나는 야후에 대한 비공개 API 요청을하려고합니다. 아래 코드를 사용했지만 작동하지 않습니다. 항상 'invalid sig'라는 메시지를 반환합니다. Two-legged OAuth Yahoo PHP 예제가 효과적입니까?두 다리가있는 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); 
} 
+0

적어도 다음 워크 플로 측면에서 도움이 될 수 있습니다. http://nullinfo.wordpress.com/oauth-yahoo/ – Ion

+0

좋은 예이지만 내 응용 프로그램에 대한 사용자 권한을 얻어야합니다. Two-legged OAuth 플로우 (사용자 권한 없음)를 만들려면 어떻게해야합니까? – Junior

답변

0

야후 사양 here에 따라 서명을 생성합니까? 또는 here과 같이 일반 텍스트 서명을 사용할 수 있습니다.