我想知道如何通过ROBLOX的用户API发送请求,但似乎并没有具体说明。我正在通过状态创建一个登录站点,我需要ID来获取用户状态。我很感谢你的帮助。
如果我绝对需要使用/v1/user/search
,我希望获得第一个用户的id。
发布于 2021-05-14 04:37:31
您只需发出一个获取请求,并从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上发布了答案。如果你需要帮助,可以随便问。
发布于 2022-07-13 21:33:57
如果您想在这里使用js,只需向https://api.roblox.com/users/get-by-username?username=UserName
发送一个get请求就可以了--它非常简单。
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch("https://api.roblox.com/users/get-by-username?username=xLeki", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));```
发布于 2020-11-24 21:03:30
您可以使用Players:GetUserIdFromNameAsync()
或此我找到的DevForm链接
这些可能是不正确的,因为游戏网站被我屏蔽了:
https://stackoverflow.com/questions/64977658
复制相似问题