学习
引擎类
RecommendationPages
无法创建
未复制

*此内容使用人工智能(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("物品ID: " .. item.ItemId)
print(" 参考ID: " .. item.ReferenceId)
print(" 跟踪ID: " .. 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 是我们在美国及其他国家或地区的注册与未注册商标。