我在Twitter帳戶中創建了一個應用程序。我試圖爲特定的hashtag獲取tweet,但我不知道如何在此運行URL和使用訪問令牌。而我無法找到JS SDK。我是twitter新人,對此感到困惑。如何通過Javascript調用twitter API
我已經找到這段代碼,但它得到了400個錯誤的請求錯誤。請幫我
$.ajax({
url: "https://api.twitter.com/1.1/statuses/user_timeline.json?",
type: "GET",
data: {count:10 },//cursor: "-1",
// screen_name: "sitestreams" },
cache: false,
dataType: 'json',
success: function(data) { alert('hello!'); console.log(data);},
error: function(html) { alert(html); },
beforeSend: setHeader
});
function setHeader(xhr) {
if(xhr && xhr.overrideMimeType) {
xhr.overrideMimeType("application/j-son;charset=UTF-8");
}
xhr.setRequestHeader('Authorization: OAuth oauth_consumer_key="qqqq7a3ansbRqqqTfOBdX4hn2sQJp72a", oauth_nonce="a3df1878qqqqe0b6d644f6ac0fd3a354725a", oauth_signature="%qqqqq2BhZ4eYIjnJc0fcHU2VHhrjvR0Ns%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1435qqqqq579396", oauth_token="468141855-Id6phQoOE66n9CBzAdqqqqwEUAuQI2qqqqTBmxGyUHL9xarx", oauth_version="1.0"');
}
如何使用這些OUTH簽名
OAuth的簽名結果
重要提示:這隻會有效期爲幾分鐘。還記得 cURL命令將實際執行請求。空 nullSignature基本字符串空 nullGET & HTTPS%3A%2F%2Fapi.twitter.com%2F1.1%2Ffriends%2Flist.json &安培%253Binclude_user_entities%3Dfalse%26安培%253Bscreen_name%3Dtwitterapi%26安培%253Bskip_status%3Dtrue%26cursor %3D-1%26oauth_consumer_key%3D7a3addsssdnsbRTfOBdX4hn2sQJp72a%26oauth_nonce%3D84d92acbc6ssssddd8ff3ecd2fa72e8dc64c4fc%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1445456635455642473%26oauth_token%3D468141855-Id6phQoOE66n9CBzAdwsddEUAuQI2TBmxGyUHL9xarx%26oauth_version%3D1.0 空nullAuthorization頭空nullAuthorization:OAuth的 oauth_consumer_key = 「7a3ansbRsssssTfOBdX4hn2sQJp72a」, oauth_nonce =「84d92acbsssc68ff3ecd2fa72e8dc64c4fc」, oauth_signature =「DThJZIUNssDNA8rtHt7R6x04aAGVM%3D」, oauth_signature_method = 「HMAC-SHA1」,oauth_timestamp = 「1435642473」, 組oauth_token = 「468145641855-Id6phQoOE66ssn9CBzAdwEUAssuQI2TBmxGyUHL9xarx」, oauth_version = 「1.0」 空nullcURL命令空nullcurl --get 'https://api.twitter.com/1.1/friends/list.json' --data 「安培%3Binclude_user_entities =假&安培%3Bscreen_name = twitterapi &安培%3Bskip_status =真&光標= -1' --header「授權:OAuth的oauth_consumer_key = 「7a3ansbRTsssfOBdX4hn2sQJp72a」, oauth_nonce = 「84d9ss2acbc68ff3ecd2fa72e8dc64c4fc」, oauth_signature = 「DThJZIUNDssssNA8rtHt7R6x04aAGVM%3D」, oauth_signature_method =「HMAC-SHA1」,oauth_timestamp =「143564542473」, oauth_token =「46814 1851235-Id6phQoOE66n9CBsssszAdwEUAuQI2TBmxGyUHL9xarx」, oauth_version =‘1.0’」 --verbose空空
您需要有一個ssl連接才能使用它們。否則,你會得到一個錯誤的請求錯誤,像你一樣 – Leb
@leb我正在本地服務器上工作。感謝您的幫助 –