Roblox Group Bot调用API遇授权验证挑战,求验证码参数及代码解决方法
我正在开发一款Roblox群组机器人,调用Roblox Group V2/1 API时,请求返回了“Challenge is required to authorize”的响应。我不知道怎么获取captchaId、captchaToken、captchaProvider和challengeId这些验证码参数,之前从没开发过机器人,还在学习阶段,附上我的Python代码,希望有人帮忙解决:
import requests import os # 替换为你的群组ID GROUP_ID = 34166526 ROBLOSECURITY_COOKIE = "nah" def get_csrf_token(): auth_url = "https://auth.roblox.com/v1/logout" xsrf_request = requests.post(auth_url, cookies={".ROBLOSECURITY": ROBLOSECURITY_COOKIE}) if xsrf_request.status_code == 401: print("无效的ROBLOSECURITY cookie,程序退出。") exit() else: print("验证成功。") return xsrf_request.headers["x-csrf-token"] def is_user_in_group(): try: csrf_token = get_csrf_token() response = requests.get(f"https://groups.roblox.com/v1/groups/{GROUP_ID}/membership", params={ "groupId": GROUP_ID, "includeNotificationPreferences": True }, headers={ "Cookie": f".ROBLOSECURITY={ROBLOSECURITY_COOKIE}", "X-CSRF-TOKEN": csrf_token }) if response.status_code == 200: print("请求成功!", response.text) else: print("请求失败!", response.text) response_json = response.json() return GROUP_ID in response_json except Exception as e: print(f"检查群组身份时出错:{e}") return False def join_group(): try: csrf_token = get_csrf_token() response = requests.post(f"https://groups.roblox.com/v1/groups/{GROUP_ID}/users", json={ "captchaId": "78417cb70582c6e31.3755809701", "captchaToken": "78417cb70582c6e31.3755809701", "captchaProvider": "string", "challengeId": "78417cb70582c6e31.3755809701" }, headers={ "Cookie": f".ROBLOSECURITY={ROBLOSECURITY_COOKIE}", "X-CSRF-TOKEN": csrf_token, "Content-Type": "application/json" }) if response.status_code == 200: print("成功加入群组!") else: print(f"加入群组失败:{response.text}") except Exception as e: print(f"加入群组时出错:{e}") def post_message_on_wall(): try: csrf_token = get_csrf_token() response = requests.post(f"https://groups.roblox.com/v2/groups/{GROUP_ID}/wall/posts", json={ "body": "你好!我是一个Roblox机器人!由Bacon制作!", "captchaId": "", "captchaToken": "78417cb70582c6e31.3755809701", "captchaProvider": "arkose-labs", "challengeId": "" }, headers={ "Cookie": f".ROBLOSECURITY={ROBLOSECURITY_COOKIE}", "Content-Type": "application/json", "X-CSRF-TOKEN": csrf_token, }) if response.status_code == 200: print("成功在群组墙发布消息!") else: print(f"发布消息失败:{response.text}") except Exception as e: print(f"发布消息时出错:{e}") if __name__ == "__main__": if not is_user_in_group(): join_group() post_message_on_wall()
问题解决思路
这个错误是Roblox触发了人机验证机制,需要通过Arkose Labs的验证流程获取所需参数,具体步骤如下:
提取验证基础参数
当收到403错误响应时,解析响应的JSON内容,里面会直接给出challengeId和captchaProvider(通常为arkose-labs)。获取Captcha ID
向https://apis.roblox.com/human-verification/v1/config发送GET请求,带上你的.ROBLOSECURITYCookie和X-CSRF-Token,响应的arkose.publicKey字段就是captchaId。完成人机验证获取Token
这一步需要模拟浏览器环境(比如用Selenium、Playwright)加载Arkose Labs的验证组件,传入captchaId和challengeId,完成验证后会生成captchaToken(即验证会话令牌)。重新发起API请求
把获取到的四个参数填入请求的JSON体中,再次调用原API接口即可通过验证。
代码修改示例(以join_group函数为例)
def join_group(): try: csrf_token = get_csrf_token() # 先发起不带验证码的请求,触发验证要求 response = requests.post(f"https://groups.roblox.com/v1/groups/{GROUP_ID}/users", json={}, headers={ "Cookie": f".ROBLOSECURITY={ROBLOSECURITY_COOKIE}", "X-CSRF-TOKEN": csrf_token, "Content-Type": "application/json" }) if response.status_code == 403 and "Challenge is required" in response.text: error_data = response.json() challenge_id = error_data["challenge"]["challengeId"] captcha_provider = error_data["challenge"]["captchaProvider"] # 获取captchaId config_response = requests.get("https://apis.roblox.com/human-verification/v1/config", headers={ "Cookie": f".ROBLOSECURITY={ROBLOSECURITY_COOKIE}", "X-CSRF-TOKEN": csrf_token }) captcha_id = config_response.json()["arkose"]["publicKey"] # 这里需要实现浏览器模拟完成Arkose验证,获取captchaToken # 示例:用Selenium打开验证页面,手动完成后提取token # captcha_token = "从验证流程中获取的有效token" # 重新发起请求(替换captcha_token为实际值) retry_response = requests.post(f"https://groups.roblox.com/v1/groups/{GROUP_ID}/users", json={ "captchaId": captcha_id, "captchaToken": captcha_token, "captchaProvider": captcha_provider, "challengeId": challenge_id }, headers={ "Cookie": f".ROBLOSECURITY={ROBLOSECURITY_COOKIE}", "X-CSRF-TOKEN": csrf_token, "Content-Type": "application/json" }) if retry_response.status_code == 200: print("成功加入群组!") else: print(f"加入群组失败:{retry_response.text}") elif response.status_code == 200: print("成功加入群组!") else: print(f"加入群组失败:{response.text}") except Exception as e: print(f"加入群组时出错:{e}")
内容的提问来源于stack exchange,提问作者rizzmasGuy
相关产品推荐
相关产品推荐

