Engine Class
RecommendationService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
วิธีการ
GenerateItemListAsync(generateRecommendationItemListRequest: Dictionary):RecommendationPages |
GetRecommendationItemAsync(itemId: string):Dictionary |
LogActionEvent(actionType: Enum.RecommendationActionType,itemId: string,tracingId: string,actionEventDetails: Dictionary):() |
LogImpressionEvent(impressionType: Enum.RecommendationImpressionType,itemId: string,tracingId: string,impressionEventDetails: Dictionary):() |
LogPreferenceEvent(preferenceType: Enum.RecommendationPreferenceType,targetType: Enum.RecommendationPreferenceTargetType,targetId: string,tracingId: string,itemId: string):() |
RegisterItemAsync(player: Player,registerRecommendationItemsRequest: Dictionary):Dictionary |
RemoveItemAsync(itemId: string):() |
UpdateItemAsync(updateRecommendationItemRequest: Dictionary):() |
เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
GenerateItemListAsync
RecommendationService:GenerateItemListAsync(generateRecommendationItemListRequest:Dictionary):RecommendationPages
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
สร้างรายการสินค้าที่แนะนำ
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)GetRecommendationItemAsync
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
รับรายการคำแนะนำเดียว
local RecommendationService = game:GetService("RecommendationService")
local function getItem(itemId)
local success, item = pcall(function()
return RecommendationService:GetRecommendationItemAsync(itemId)
end)
if success and item then
print("ดึงรายการสำเร็จ: " .. item.ItemId)
print(" ReferenceId: " .. item.ReferenceId)
-- TracingId จะว่างเปล่าเมื่อดึงรายการเดียวโดยตรง
if item.Creator then
print(" CreatorId: " .. tostring(item.Creator.CreatorId))
end
if item.CustomTags then
print(" CustomTags: ")
for _, customTag in ipairs(item.CustomTags) do
print(" " .. customTag)
end
end
else
warn("ไม่สามารถดึงรายการได้: " .. itemId .. ". ข้อผิดพลาด: " .. tostring(item))
end
end
-- ตัวอย่างการใช้งาน (ต้องมี itemId ที่ถูกต้อง)
-- getItem("some-item-id")LogActionEvent
RecommendationService:LogActionEvent(
actionType:Enum.RecommendationActionType, itemId:string, tracingId:string, actionEventDetails:Dictionary
):()
พารามิเตอร์
| ค่าเริ่มต้น: "nil" |
ส่งค่ากลับ
()
ตัวอย่างโค้ด
การบันทึกการกระทำของผู้ใช้
local RecommendationService = game:GetService("RecommendationService")
local function logLike(itemId, tracingId)
local detail: RecommendationActionEventDetails = {
ReactionType = "Like",
Weight = 1.0
}
RecommendationService:LogActionEvent(Enum.RecommendationActionType.AddReaction, itemId, tracingId, detail)
print("บันทึกการกระทำ 'Like' สำหรับรายการ: " .. itemId)
end
-- ตัวอย่างการใช้งาน (ต้องมี itemId และ tracingId ที่ถูกต้องจาก GenerateItemListAsync)
-- logLike("item-id", "tracing-id")LogImpressionEvent
RecommendationService:LogImpressionEvent(
impressionType:Enum.RecommendationImpressionType, itemId:string, tracingId:string, impressionEventDetails:Dictionary
):()
พารามิเตอร์
| ค่าเริ่มต้น: "nil" |
ส่งค่ากลับ
()
ตัวอย่างโค้ด
บันทึกการแสดงผลของผู้ใช้
local RecommendationService = game:GetService("RecommendationService")
local function logView(itemId, tracingId)
local detail: RecommendationImpressionEventDetails = {
Duration = 5, -- ผู้ดูรายการเป็นเวลา 5 วินาที
ItemPosition = 1,
DepartureIntent = Enum.RecommendationDepartureIntent.Neutral
}
RecommendationService:LogImpressionEvent(Enum.RecommendationImpressionType.View, itemId, tracingId, detail)
print("บันทึกการแสดงผล 'ดู' สำหรับรายการ: " .. itemId)
end
-- การใช้งานตัวอย่าง (ต้องการ itemId และ tracingId ที่ถูกต้องจาก GenerateItemListAsync)
-- logView("some-item-id", "some-tracing-id")LogPreferenceEvent
RecommendationService:LogPreferenceEvent(
preferenceType:Enum.RecommendationPreferenceType, targetType:Enum.RecommendationPreferenceTargetType, targetId:string, tracingId:string, itemId:string
):()
พารามิเตอร์
ส่งค่ากลับ
()
RegisterItemAsync
RecommendationService:RegisterItemAsync(
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
ลงทะเบียนรายการใหม่
local RecommendationService = game:GetService("RecommendationService")
local storage = game:GetService("ReplicatedStorage")
-- สมมติว่ามี RemoteFunction ชื่อ 'RegisterItemRemote' อยู่ใน ReplicatedStorage
local registerItemRemote = storage.RegisterItemRemote
registerItemRemote.OnServerInvoke = function(player, refId)
local request: RegisterRecommendationItemRequest = {
ContentType = Enum.RecommendationItemContentType.Dynamic,
ReferenceId = refId,
Duration = 60,
Visibility = Enum.RecommendationItemVisibility.Public,
CustomTags = {"locale:th-th", "seasonal:summer"},
Attributes = {
{
AssetId = 123,
Description = "test video",
TrimStartTime = 0,
TrimEndTime = 10.5
}
}
}
local success, response = pcall(function()
return RecommendationService:RegisterItemAsync(player, request)
end)
if success and response then
print("ลงทะเบียนรายการสำเร็จ รายการ Id: " .. response.ItemId)
return response.ItemId
else
warn("ลงทะเบียนรายการล้มเหลว ข้อผิดพลาด: " .. tostring(response))
return nil
end
endRemoveItemAsync
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
ลบรายการ
local RecommendationService = game:GetService("RecommendationService")
local function removeItem(itemId)
local success, err = pcall(function()
return RecommendationService:RemoveItemAsync(itemId)
end)
if success then
print("ลบรายการสำเร็จ: " .. itemId)
else
warn("ไม่สามารถลบรายการ: " .. itemId .. ". ข้อผิดพลาด: " .. tostring(err))
end
endUpdateItemAsync
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
อัปเดตไอเท็ม
local RecommendationService = game:GetService("RecommendationService")
local function updateItem(itemId)
-- รวมเฉพาะฟิลด์ที่คุณต้องการอัปเดต
local request: UpdateRecommendationItemRequest = {
ItemId = itemId,
Visibility = Enum.RecommendationItemVisibility.Private,
-- หมายเหตุ: รายการ CustomTags ทั้งหมดจะถูกแทนที่ด้วยรายการใหม่นี้
CustomTags = {"updated-tag"}
}
local success, err = pcall(function()
return RecommendationService:UpdateItemAsync(request)
end)
if success then
print("อัปเดตไอเท็มเรียบร้อยแล้ว: " .. itemId)
else
warn("ไม่สามารถอัปเดตไอเท็ม: " .. itemId .. ". ข้อผิดพลาด: " .. tostring(err))
end
end
-- ตัวอย่างการใช้งาน
-- updateItem("some-item-id-to-update")