在访问 Twitter API [ROBLOX STUDIO] 时出现 401 未经授权的错误

我很少在这里发帖,但我觉得有必要这样做,所以我在这里。如果你看了标题,我来自 ROBLOX STUDIO,因为 bearer token 包含"%",我不能使用它,除非我使用代理来代替它。我尝试的替代方法是这个:

local http = game:GetService("HttpService")
local base64 = require(script.Base64)
local consumerkey = "myConsumerKeyHere"
local secretkey = "mySecretKeyHere"

local resp =http:PostAsync("https://api.twitter.com/oauth2/token", "grant_type=client_credentials", Enum.HttpContentType.ApplicationUrlEncoded, false, {Authorization = "Basic " .. base64.encode(consumerkey .. ":" .. secretkey)})

local auth = http:JSONDecode(resp).access_token:gsub("%%%x%x", function(match) return string.char(tonumber(match:sub(2), 16)) end)

-- 这里是错误的地方 --    local results = http:GetAsync("https://api.twitter.com/1.1/followers/list.json?cursor=-1&screen_name=basicallyrbx&skip_status=true&include_user_entities=false",false,{["Authorization"] = "Bearer " .. auth})
local finalThing = http:JSONDecode(results)

print(finalThing)

我遇到的错误出现在我勾画出的那一行 (studio 中的第 11 行)。是什么原因导致了 HTTP 401 的出现?任何帮助都将不胜感激!

原文链接 https://stackoverflow.com/questions/70441117

点赞