通过用户名获取 ID (Roblox)
Get ID by username (Roblox)
我想知道如何通过 ROBLOX's User API 发送请求,但似乎没有具体记录。
我正在通过状态登录网站,我需要 ID 来获取用户状态。感谢您提供的任何帮助。
如果我绝对需要使用/v1/user/search
,我想获取第一个用户的id
您可以使用Players:GetUserIdFromNameAsync()
or this DevForm link I found
这些可能不正确,因为游戏网站对我来说被屏蔽了:(
要获取用户名,您可以使用 https://users.roblox.com/v1/users/<USER ID>
,同时获取用户的状态,您需要 https://users.roblox.com/v1/users/<USER ID>/status
。
您只需发出一个提取请求并从 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);
})
}
抱歉,我是第一次在 Whosebug 上发布答案。如果您需要任何帮助,请随时提出。
我想知道如何通过 ROBLOX's User API 发送请求,但似乎没有具体记录。 我正在通过状态登录网站,我需要 ID 来获取用户状态。感谢您提供的任何帮助。
如果我绝对需要使用/v1/user/search
,我想获取第一个用户的id
您可以使用Players:GetUserIdFromNameAsync()
or this DevForm link I found
这些可能不正确,因为游戏网站对我来说被屏蔽了:(
要获取用户名,您可以使用 https://users.roblox.com/v1/users/<USER ID>
,同时获取用户的状态,您需要 https://users.roblox.com/v1/users/<USER ID>/status
。
您只需发出一个提取请求并从 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);
})
}
抱歉,我是第一次在 Whosebug 上发布答案。如果您需要任何帮助,请随时提出。