學習
引擎類別
RecommendationPages
無法建立
未複製

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


概要

繼承成員
範例程式碼
生成推薦物品列表
local RecommendationService = game:GetService("RecommendationService")
-- 定義生成推薦列表的請求
local request: GenerateRecommendationItemListRequest = {
ConfigName = "MaximizeEngagement",
LocationId = "Lobby",
PageSize = 10
-- 注意:取消註解並設置 CustomContexts.UserId 用於伺服器腳本。
-- 本地腳本不需要設置。
-- CustomContexts = {
-- ["UserId"] = tostring(player.UserId),
-- }
}
-- 調用 GenerateItemListAsync 獲取推薦頁面
local success, recommendationPages = pcall(function()
return RecommendationService:GenerateItemListAsync(request)
end)
if success then
-- 獲取當前推薦物品頁面
local currentPage = recommendationPages:GetCurrentPage()
for _, item in ipairs(currentPage) do
print("ItemId: " .. item.ItemId)
print(" ReferenceId: " .. item.ReferenceId)
print(" TracingId: " .. item.TracingId)
end
else
warn("RecommendationService 錯誤: " .. tostring(recommendationPages))
end
--[[ 返回的數據格式,每個頁面中的項目
{
"ItemId": string,
"ReferenceId": string,
"TracingId": string,
"Creator": {
"CreatorId": number,
"CreatorType": Enum.CreatorType,
}?,
"Attributes": {
{
"AssetId": number?,
"Text": string?,
"Description": string?,
"SeekStartTime": number?,
"SeekEndTime": number?,
"TrimStartTime": number?,
"TrimEndTime": number?
}
}?,
"CustomTags": { string }?
}
--]]
©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。