【发布时间】:2014-02-18 05:58:32
【问题描述】:
我无法通过 JQuery 对 twitter API 进行 Ajax 调用。我的问题是授权。这就是我正在做的,对我来说似乎没问题:
function loadTwitter(sLat, sLon, sRad, dFrom, dTo){
arrayTweets = new Array();
var sRadKm = sRad/1000;
dFrom = dFrom/1000;
dTo = dTo/1000;
var twitterUrlPath = "https://api.twitter.com/1.1/search/tweets.json";
var auth = "OAuth oauth_consumer_key='0kfWFbA6xxxrKjpg2oQ', oauth_nonce='87abf089674bxxx8bd50823c500c', oauth_signature='URF2O%2BdSS0ExxxP8pqQWnA%3D', oauth_signature_method='HMAC-SHA1', oauth_timestamp='1390287341', oauth_token='2287933520-fuUBrz3AZ0GoopxxxxsfE4nLZZ5QJryB8cFZuR0', oauth_version='1.1'";
var urlTwitter = "?geocode=" + sLat + "," + sLon + "," + sRadKm + "km&count=100";
$.ajax({
type: "GET",
async: false,
accept: "application/json",
url: twitterUrlPath + urlTwitter,
dataType: "jsonp",
beforeSend : function(req) {
req.setRequestHeader('Authorization', auth);
},
success: function (resp, status, xhr) {
$("#message").html("STATUS: " + xhr.status + " " + xhr.statusText + "\n" + resp);
$("#message").hide();
$.each(resp, function() {
$.each(this, function(i, item) {
arrayTweets.push(item);
});
});
displayTweets();
},
error: function(resp, status, xhr){
$("#message").html("ERROR: " + xhr.status + " " + xhr.statusText + "\n" + resp.e);
$("#message").show();
}
});
}
我不断收到 400 Bad Request。
另外,如果我想通过海报(firefox 嗅探器)调用它,我如何传递 auth 参数? 谢谢,
【问题讨论】:
标签: javascript jquery ajax twitter twitter-oauth