亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法使用 Twitter V1.1 API 驗證用戶身份

無法使用 Twitter V1.1 API 驗證用戶身份

PHP
慕斯王 2023-10-22 21:30:11
我已經通過創建簽名實現了一切。我創建了一個函數來收集所需的參數(為了清楚起見,我在此處添加了一些注釋):function collect_parameters(){    global $credentials; // This is an Object with my App's credentials and stuff    $oAuth = get_user_oauth();  // This returns an object with the the personal user OAuth tokens retrieved from the earlier docs.    $encoded_collection = array();    $collection = array(        'status'                 => rawurlencode( $_GET['tweet'] ),        'include_entities'       => 'true',        'oauth_consumer_key'     => $credentials->key,        'oauth_nonce'            => $credentials->nonce, // md5( str_shuffle( uniqid() . mt_rand(0,9999999999) ) )        'oauth_signature_method' => 'HMAC-SHA1',        'oauth_timestamp'        => $credentials->time, // current timestamp        'oauth_token'            => $oAuth->oauth_token,        'oauth_version'          => '1.0',    );    // Percent encode every key and value that will be signed.    foreach( $collection as $key => $value ){        $encoded_collection[rawurlencode($key)] = rawurlencode($value);     }    // Sort the list of parameters alphabetically by encoded key.    ksort( $encoded_collection );    return http_build_query( $encoded_collection );}我使用這個函數來構建簽名基字符串function create_signature_base_string( $parameter_string, $url = 'https://api.twitter.com/1.1/statuses/update.json', $method = 'POST' ){    return strtoupper( $method ) .'&'. rawurlencode( $url ) .'&'. rawurlencode( $parameter_string );}我用這個函數來計算簽名function calculate_signature( $signature_base_string, $signing_key ){    return base64_encode( hash_hmac('sha1', $signature_base_string, $signing_key, true) );}現在構建 OAuth 標頭。這是一個函數,它使用上面的輔助函數(加上其他一些返回所需信息的函數):function get_oauth_headers(){    global $credentials;    $oAuth = get_user_oauth();        $parameters = collect_parameters();    $signature_base_string = create_signature_base_string( $parameters );    $signing_key = get_signing_key();    $signature = calculate_signature( $signature_base_string, $signing_key );    );
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 154 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號