2012-02-09 8 views
3

これは私のクラッカーを運転しています。私はウェブサイト上に友人招待制度を実装しており、ユーザーのYahoo連絡先リストにアクセスする必要があります。これを行うには、OAuthとyahoo REST APIを使用しています。ここにイベントのシーケンスの完全な概要があります:私はYahooの連絡先APIに私の電話からHTTP 401 Unauthorizedを取得するのはなぜですか?

連絡先への読み取りアクセス権を持つように設定されているdevelopers.yahoo.comでプロジェクトをセットアップしました。私のホストファイルで127.0.0.1を指し示しているメークアップドメインにあります(ローカルホストが私の不幸を引き起こしていた可能性があります)。この理由から、私の理解は、これは単純に私は制限が少なく、それ以上ではないことを意味するが、ドメインは検証されない。

で返し
https://api.login.yahoo.com/oauth/v2/get_request_token 
    ?oauth_callback=http%3A%2F%2Fdev.mysite.com%2Fcallback.aspx 
    &oauth_consumer_key=MYCONSUMERKEY-- 
    &oauth_nonce=xmaf8ol87uxwkxij 
    &oauth_signature=WyWWIsjN1ANeiRpZxa73XBqZ2tQ%3D 
    &oauth_signature_method=HMAC-SHA1 
    &oauth_timestamp=1328796736 
    &oauth_version=1.0 

(明確であいまいな試み用にフォーマット済み):

oauth_token=hxcsqgj 
&oauth_token_secret=18d01302348049830942830942630be6bee5 
&oauth_expires_in=3600 
&xoauth_request_auth_url 
    =https%3A%2F%2Fapi.login.yahoo.com%2Foauth%2Fv2%2Frequest_auth 
    %3Foauth_token%3Dhxcsqgj 
&oauth_callback_confirmed=true" 

が、私はその後、ポップアップにxoauth_request_auth_urlページを

はまず、サーバー上で私がリクエストトークンを取得しますユーザーは私のコールバックページに検証コードを受け取ります。私がアクセストークンに交換できるように、私はその後、私のサーバーにその背中を送信します。

https://api.login.yahoo.com/oauth/v2/get_token 
    ?oauth_consumer_key=MYCONSUMERKEY-- 
    &oauth_nonce=yxhd1nymwd03x189 
    &oauth_signature=c%2F6GTcybGJSQi4TOpvueLUO%2Fgrs%3D 
    &oauth_signature_method=HMAC-SHA1 
    &oauth_timestamp=1328796878 
    &oauth_token=hxcqgjs 
    &oauth_verifier=b8ngvp  <- verifier given via callback 
    &oauth_version=1.0 

動作するようだ、と私はトークンバックのアクセスを取得:

oauth_token=MYVERYLONGACCESSTOKEN-- 
&oauth_token_secret=MYOATHTOKENSECRET 
&oauth_expires_in=3600 
&oauth_session_handle=ADuXM093mTB4bgJPKby2lWeKvzrabvCrmjuAfrmA6mh5lEZUIin6 
&oauth_authorization_expires_in=818686769 
&xoauth_yahoo_guid=MYYAHOOGUID 

私は、その後すぐにしようアクセストークンとGUIDと連絡先リストを取得するには:この呼び出しから

http://social.yahooapis.com/v1/user/MYYAHOOGUID/contacts 

(HTTP Header added and formatted with line breaks for clarity...) 

Authorization: OAuth 
    realm="yahooapis.com", 
    oauth_consumer_key="MYCONSUMERKEY--", 
    oauth_nonce="nzffzj5v82mgf4mx", 
    oauth_signature="moVJywesuGaPN5YHYKqra4T2ips%3D", 
    oauth_signature_method="HMAC-SHA1", 
    oauth_timestamp="1328796907", 
    oauth_token="MYVERYLONGACCESSTOKEN--", 
    oauth_version="1.0" 

私は無断401を得るが、理由を見つけることは不可能と思われます。これらの通話に署名するには、this oath lib on githubを使用しています。私はそれが何か特別なことをしているとは思いません。署名については、コンシューマキー/シークレットとアクセストークン/シークレットを含めています。私は、ハッシュされている署名ベースを見てきました。これはyahooのドキュメントに表示されている例と同じ形式に見えます。私は、ハッシュされていないパラメータから何かを逃していると思います。コールが許可されていない理由を知る方法はありますか、誰がシグネチャベースと承認ヘッダーがどのような形で正確に表示されているかを示す例を知っていますか?

+1

http://oauth.net/core/を1.0a /#http_codes – aitchnyu

+0

こんにちはizb、私はhttp://developer.yahoo.com/oauth/guide/oauth-auth-flow.htmlの手順に従うが、私はステップ4で立ち往生した(要求トークンとOAuthを交換するアクセストークンの検証者)。アクセストークンを取得するためのURLを作成すると、「irefoxはhttps://api.login.yahoo.com/oauth/v2/get_token?oauth_consumer_key = ........でファイルを見つけることができません」というエラーが表示されます。 、 私を助けてください。 –

答えて

3

これを解決しました。ちょうどそれが私がした同じ愚かな間違いをする人を助ける場合に備えて、答えを加える。 APIコールを作成したとき、アクセストークン呼び出しから返された新しいトークントークンではなく、元のリクエストトークン呼び出しから返されたトークンシークレットを使用していました。

+0

こんにちは私はここでこの問題に直面しています。 'oauth_signature'で' oauth_token'(アクセストークン)と一緒に連絡先を要求する際に、 – Nezam

0

これはyahooapisは禁じ403を返した場合、私は、使用するために信頼されたコードを解かれるコードです:

参考: https://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_php https://github.com/danzisi/YQLQueryYahooapis

init CODE 

/** 
* Call the Yahoo Contact API 
* 
* https://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_php 
* 
* @param string $consumer_key obtained when you registered your app 
* @param string $consumer_secret obtained when you registered your app 
* @param string $guid obtained from getacctok 
* @param string $access_token obtained from getacctok 
* @param string $access_token_secret obtained from getacctok 
* @param bool $usePost use HTTP POST instead of GET 
* @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header 
* @return response string with token or empty array on error 
*/ 
function call_yql($consumer_key, $consumer_secret, $querynum, $access_token, $access_token_secret, $oauth_session_handle, $usePost=false, $passOAuthInHeader = true){ 
    global $godebug; 
    $response = array(); 

    if ($consumer_key=='' || $consumer_secret=='' || $querynum=='' || $access_token=='' || $access_token_secret=='' || $oauth_session_handle) return array('0' => 'Forbidden'); 

    if ($querynum == 1) { 
    $url = 'https://query.yahooapis.com/v1/yql'; 
    // Show my profile 
    $params['q'] = 'select * from social.profile where guid=me'; 
    } elseif ($querynum == 2) { 
    $url = 'https://query.yahooapis.com/v1/yql'; 
    // here other query 

    } 

    $params['format'] = 'json'; //json xml 
    $params['Authorization'] = 'OAuth'; 
    $params['oauth_session_handle'] = $oauth_session_handle; 
    $params['realm'] = 'yahooapis.com'; 
    $params['callback'] = 'cbfunc'; 
    $params['oauth_version'] = '1.0'; 
    $params['oauth_nonce'] = mt_rand(); 
    $params['oauth_timestamp'] = time(); 
    $params['oauth_consumer_key'] = $consumer_key; 
    $params['oauth_callback'] = 'oob'; 
    $params['oauth_token'] = $access_token; 

    $params['oauth_signature_method'] = 'HMAC-SHA1'; 
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret); 

    if ($passOAuthInHeader) { 
    $query_parameter_string = oauth_http_build_query($params, true); 
    $header = build_oauth_header($params, "yahooapis.com"); 
    $headers[] = $header; 
    } else { 
    $query_parameter_string = oauth_http_build_query($params); 
    } 

    // POST or GET the request 
    if ($usePost) { 
    $request_url = $url; 
    logit("call_yql:INFO:request_url:$request_url"); 
    logit("call_yql:INFO:post_body:$query_parameter_string"); 
    $headers[] = 'Content-Type: application/x-www-form-urlencoded'; 
    $response = do_post($request_url, $query_parameter_string, 443, $headers); 
    } else { 
    $request_url = $url . ($query_parameter_string ? ('?' . $query_parameter_string) : ''); 
    logit("call_yql:INFO:request_url:$request_url"); 
    $response = do_get($request_url, 443, $headers); 
    } 

    // extract successful response 
    if (! empty($response)) { 
    list($info, $header, $body) = $response; 

    if ($godebug==true) { 
     echo "<p>Debug: function call_yql info: <pre>" . print_r($info, TRUE) . "</pre></p>"; 
     echo "<p>Debug: function call_yql header: <pre>" . print_r($header, TRUE) . "</pre></p>"; 
     echo "<p>Debug: function call_yql body: <pre>" . print_r($body, TRUE) . "</pre></p>"; 
    } 
    if ($body) { 
     $body = GetBetween($body, 'cbfunc(', ')'); 
     $full_array_body = json_decode($body); 
     logit("call_yql:INFO:response:"); 
     if ($godebug==true) echo "<p>Debug: function call_yql full_array_body: <pre>" . print_r($full_array_body, TRUE) . "</pre></p>"; 
     } 

    } 
    // return object 
    return $full_array_body->query; 
} 
    END code 
関連する問題