【问题标题】:Get ID by username (Roblox)通过用户名获取 ID (Roblox)
【发布时间】:2021-03-06 17:07:44
【问题描述】:

我想知道如何通过ROBLOX's User API 发送请求,但似乎没有具体记录。 我正在通过状态登录站点,我需要 ID 来获取用户状态。感谢您提供的任何帮助。


如果我绝对需要使用/v1/user/search,我想获取第一个用户的ID。

【问题讨论】:

    标签: javascript html api roblox


    【解决方案1】:

    您只需发出一个获取请求并从 URL 中获取用户 ID。

    function getUserID(name)
    {
        return new Promise((res, rej) => {
            fetch(`https://www.roblox.com/users/profile?username=${name}`)
                .then(r => {
                    // check to see if URL is invalid.
                    if (!r.ok) { throw "Invalid response"; }
                    // return the only digits in the URL "the User ID"
                    return r.url.match(/\d+/)[0];
                })
                .then(id =>{
                    // this is where you get your ID
                    console.log(id);
                })
        })
    }
    
    // without Promise
    
    function getUserID(name)
    {
        fetch(`https://www.roblox.com/users/profile?username=${name}`)
            .then(r => {
                if (!r.ok) { throw "Invalid response"; }
                return r.url.match(/\d+/)[0];
            })
            .then(id => {
                console.log(id);
            })
    }
    

    抱歉,我是在 StackOverflow 上发布答案的新手。如果您需要任何帮助,请随时提出。

    【讨论】:

      【解决方案2】:

      您可以使用Players:GetUserIdFromNameAsync() 或此DevForm link I found

      这些可能是不正确的,因为我的游戏网站被屏蔽了:(

      【讨论】:

      • 我不是在找lua,但还是谢谢你!
      【解决方案3】:

      要获取用户名可以使用https://users.roblox.com/v1/users/<USER ID>,同时获取用户状态需要https://users.roblox.com/v1/users/<USER ID>/status

      【讨论】:

        猜你喜欢
        • 2020-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-09
        • 2023-01-20
        • 2017-08-24
        • 2021-05-01
        • 1970-01-01
        相关资源
        最近更新 更多