5 回答

TA貢獻1860條經(jīng)驗 獲得超9個贊
您只需發(fā)出一個提取請求并從 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);
? ? ? ? })
}

TA貢獻1712條經(jīng)驗 獲得超3個贊
https://api.roblox.com/users/get-by-username?username=UserName如果你想在此處使用 js,只需向它發(fā)送一個獲取請求就非常簡單。
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));```

TA貢獻1829條經(jīng)驗 獲得超4個贊
導入請求導入 json
def get_user_id(用戶名):
url = 'https://users.roblox.com/v1/usernames/users'
# Request body as a JSON string
request_body = {
'usernames': [username],
'excludeBannedUsers': True
}
json_data = json.dumps(request_body)
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.post(url, headers=headers, data=json_data)
user_data = json.loads(response.text)
if len(user_data['data']) > 0:
user_id = user_data['data'][0]['id']
return user_id
else:
return None
username = 'lilboii36' user_id = get_user_id(username) if user_id: print(f"User ID for {username}: {user_id}") else: print(f"No user found with username {username}")

TA貢獻1796條經(jīng)驗 獲得超4個贊
獲取您可以使用的用戶名https://users.roblox.com/v1/users/<USER ID>
,同時獲取您需要的用戶狀態(tài)https://users.roblox.com/v1/users/<USER ID>/status
。
添加回答
舉報