Mojang API 身份验证令牌。 Discord.js

发布于 2025-01-10 03:19:08 字数 1416 浏览 0 评论 0原文

所以我试图从 Mojang API 获取一些东西,我试图获取某个名称是否可用。但我不知道如何获取身份验证令牌来发送请求。有人可以解释一下如何获取令牌来发送请求。我尝试过的一切都没有奏效。我收到的最远的是 401 错误。 我试过 axios

            axios({
                headers: { Authorization: '<api key>'},
                url: '/minecraft/profile/name/userbruh/available',
                method: 'get'
              })
              .then(function (response) {
                console.log(response);
              })
              .catch(function (error) {

                  console.log(error);
              });

没用 我尝试了普通的节点 HTTP 请求,

            const options = {
              hostname: 'api.minecraftservices.com/minecraft/profile/name/userbruh/available',
              path: '/minecraft/profile/name/userbruh/available',
              method: 'GET',
              headers: {
                'Authorization': '<api-key>'
              }
            }
            
            const req = https.request(options, res => {
              console.log(`statusCode: ${res.statusCode}`)
            
              res.on('data', d => {
                process.stdout.write(d)
              })
            })
            
            req.on('error', error => {
              console.error(error)
            })
            
            req.end()

但这也不起作用,我只是不知道我应该做什么。哦,我从 minecraft.net 页面的帐户中的不记名令牌中获取了身份验证令牌 请有人帮我尝试获取这个 Mojang Bearer 令牌

So I am trying to get something from Mojang API I'm trying to get if a certain name is available. But I cant figure out how I am supposed to get the authentication token to send the request. Can someone explain how do I get the token to send the request. And Everything That I have tried hasnt worked. The Furthest I have gotten is a 401 error.
I tried axios

            axios({
                headers: { Authorization: '<api key>'},
                url: '/minecraft/profile/name/userbruh/available',
                method: 'get'
              })
              .then(function (response) {
                console.log(response);
              })
              .catch(function (error) {

                  console.log(error);
              });

It didnt work
I tried normal node HTTP requests

            const options = {
              hostname: 'api.minecraftservices.com/minecraft/profile/name/userbruh/available',
              path: '/minecraft/profile/name/userbruh/available',
              method: 'GET',
              headers: {
                'Authorization': '<api-key>'
              }
            }
            
            const req = https.request(options, res => {
              console.log(`statusCode: ${res.statusCode}`)
            
              res.on('data', d => {
                process.stdout.write(d)
              })
            })
            
            req.on('error', error => {
              console.error(error)
            })
            
            req.end()

That didnt work either and I just cant find out what im supposed to do. Oh I got the auth token from the bearer token in from my account from the minecraft.net page
Someone please help me try to get this Mojang Bearer token

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

懒猫 2025-01-17 03:19:08

tl;dr:您需要按照下面的身份验证流程之一来获取该请求的令牌。

当 Microsoft 购买 Minecraft 时,他们彻底修改了身份验证步骤和方法。开始将 Minecraft 帐户迁移到 Microsoft 帐户。由于这仍然是一个正在进行的过程,因此目前存在两个身份验证流程。值得庆幸的是,它们有很好的记录:

较新的版本自然更加迟钝并且实现起来很痛苦,但是该页面底部有各种语言的参考实现。快乐编码!

tl;dr: You need to follow one of the auth flows below to attain the token for that request.

When Microsoft bought Minecraft, they overhauled the authentication steps & started migrating Minecraft account to Microsoft ones. Since that's still an ongoing process so there's two auth flows that exist at the moment. Thankfully, they're very well documented:

The newer is naturally much more obtuse and a pain to implement, but there are reference implementations in various languages at the bottom of that page. Happy coding!

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