Datatype.Secret 資料類型儲存 HttpService:GetSecret() 返回的秘密內容。它不能打印或儲存,但可以使用內置功能修改,如下代碼示範所示。
local HttpService = game:GetService("HttpService")local mySiteApiKey = HttpService:GetSecret("my_site")local url = "https://apis.mysite.com?apiKey="local urlWithKey = mySiteApiKey:AddPrefix(url)local params = "&request=join&user=myname"local resultingUrl = urlWithKey:AddSuffix(params)
方法
AddSuffix
返回原始秘密和指定的字串參數的結合。 對於包含鑰匙和查詢參數的 URL 很有用。
local HttpService = game:GetService("HttpService")local googleMapsApiKey = HttpService:GetSecret("google_map")local baseUrl = "https://maps.googleapis.com/maps/api/distancematrix/json?key="local queryParams = "&destinations=" .. destination .. "&origins=" .. origin .. "&departure_time=now&units=imperial"local authedUrl = googleMapsApiKey:AddPrefix(baseUrl)local queryUrl = authedUrl:AddSuffix(queryParams)