【发布时间】:2017-03-15 07:32:54
【问题描述】:
我们正在使用邮递员发送请求,其中包含正确的授权参数和我们的访问密钥,该密钥返回我们正在寻找的 JSON,但是在我们的 javascript 中,我们尝试使用 ajax 和 jsonp 发送请求,但得到了 401尝试这样做时出现响应错误。这是我们的代码。
shopButton.click(() => {
// The getJSON function initiates a connection to the web service.
$.ajax({
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=adidasalerts&count=3',
dataType: 'jsonp',
headers: {
'Authorization':'Bearer REDACTED',
}
success: function(dataWeGotViaJsonp){
console.log(dataWeGotViaJsonp)
}
});
});
我们知道我们的访问令牌有效,因为我们可以使用 Postman 发送请求。有没有人有任何想法?在我们尝试使用 $.getJSON 之前,我们不断收到跨域域错误。
【问题讨论】:
标签: javascript jquery json ajax twitter