在尝试通过Twitter API关注用户时会出错

发布于 2025-02-09 13:59:31 字数 624 浏览 1 评论 0原文

我正在尝试通过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'
            }
        })

i am trying to connect twitter API of getting friends (followers) of user via twitter's api with endpoint that mentioned here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2025-02-16 13:59:31

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文