在尝试通过Twitter API关注用户时会出错
我正在尝试通过Twitter的twitter api的twitter api(关注者)通过twitter的api连接到此处提到的
https://api.twitter.com/1.1/friends/list.json
我遇到的错误是关于CORS的,尽管我从浏览器方面进行了管理
,这是我用于Fetch用户的代码
const response = await fetch('https://api.twitter.com/1.1/friends/list.json',{
method: 'GET',
headers : {
"Content-Type": "application/json;charset=UTF-8",
'Authorization' : 'Bearer my_token'
}
})
https://api.twitter.com/1.1/friends/list.json
Error that i am getting is that about cors, though i have manage it from browser side
Here is my code that i use for fetch user
const response = await fetch('https://api.twitter.com/1.1/friends/list.json',{
method: 'GET',
headers : {
"Content-Type": "application/json;charset=UTF-8",
'Authorization' : 'Bearer my_token'
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Twitter API不支持CORS,您不能以这种方式以浏览器调用。您需要使用服务器端代码。
(此外,您要使用的v1.1 API是旧的API,您最好看v2-等效的是 lookup 功能)
The Twitter API does not support CORS and you cannot call it in a browser in this manner. You will need to use server-side code.
(additionally, the v1.1 API you are trying to use is a legacy API and you would be better to look at v2 - the equivalent is the Follows lookup functionality)