Recommendation Service
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm tắt
Phương Pháp
GenerateItemListAsync(generateRecommendationItemListRequest: GenerateRecommendationItemListRequest):RecommendationPages |
GetRecommendationItemAsync(itemId: string):Dictionary |
LogActionEvent(actionType: Enum.RecommendationActionType,itemId: string,tracingId: string,actionEventDetails: RecommendationActionEventDetails):() |
LogImpressionEvent(impressionType: Enum.RecommendationImpressionType,itemId: string,tracingId: string,impressionEventDetails: RecommendationImpressionEventDetails):() |
LogPreferenceEvent(preferenceType: Enum.RecommendationPreferenceType,targetType: Enum.RecommendationPreferenceTargetType,targetId: string,tracingId: string,itemId: string):() |
RegisterItemAsync(player: Player,registerRecommendationItemsRequest: RegisterRecommendationItemRequest):Dictionary |
RemoveItemAsync(itemId: string):() |
UpdateItemAsync(updateRecommendationItemRequest: UpdateRecommendationItemRequest):() |
Tài Liệu Tham Khảo API
Phương Pháp
Generate Item List Async
Recommendation Service: Generate Item List Async(generate Recommendation Item List Request:GenerateRecommendationItemListRequest):RecommendationPages
Tham Số
generateRecommendationItemListRequest:GenerateRecommendationItemListRequest |
Lợi Nhuận
Mẫu mã
Tạo danh sách các mục được đề xuất
local RecommendationService = game:GetService("RecommendationService")
-- Định nghĩa yêu cầu để tạo danh sách gợi ý
local request: GenerateRecommendationItemListRequest = {
ConfigName = "MaximizeEngagement",
LocationId = "Lobby",
PageSize = 10
-- LƯU Ý: Bỏ chú thích và đặt CustomContexts.UserId cho script Server.
-- Không cần đặt cho script Local.
-- CustomContexts = {
-- ["UserId"] = tostring(player.UserId),
-- }
}
-- Gọi GenerateItemListAsync để lấy các trang gợi ý
local success, recommendationPages = pcall(function()
return RecommendationService:GenerateItemListAsync(request)
end)
if success then
print("Các trang gợi ý đã được tạo:", recommendationPages)
else
warn("Không thể tạo gợi ý:", recommendationPages)
endGet Recommendation Item Async
Tham Số
Lợi Nhuận
Mẫu mã
Lấy một mục đề xuất đơn
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("Đã lấy item thành công: " .. item.ItemId)
print(" ReferenceId: " .. item.ReferenceId)
-- TracingId sẽ trống khi lấy một item đơn lẻ trực tiếp
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("Không thể lấy item: " .. itemId .. ". Lỗi: " .. tostring(item))
end
end
-- Ví dụ sử dụng (cần một itemId hợp lệ)
getItem("some-item-id")Log Action Event
Recommendation Service: Log Action Event(
action Type:Enum.RecommendationActionType, item Id:string, tracing Id:string, action Event Details:RecommendationActionEventDetails
):()
Tham Số
actionEventDetails:RecommendationActionEventDetails Giá Trị Mặc Định: nil |
Lợi Nhuận
()
Mẫu mã
Ghi lại hành động của người dùng
local RecommendationService = game:GetService("RecommendationService")
local function logLike(itemId, tracingId)
local detail: RecommendationActionEventDetails = {
ReactionType = "Thích",
Weight = 1.0
}
RecommendationService:LogActionEvent(Enum.RecommendationActionType.AddReaction, itemId, tracingId, detail)
print("Đã ghi lại hành động 'Thích' cho mục: " .. itemId)
end
-- Ví dụ sử dụng (cần một itemId và tracingId hợp lệ từ GenerateItemListAsync)
logLike("item-id", "tracing-id")Log Impression Event
Recommendation Service: Log Impression Event(
impression Type:Enum.RecommendationImpressionType, item Id:string, tracing Id:string, impression Event Details:RecommendationImpressionEventDetails
):()
Tham Số
impressionEventDetails:RecommendationImpressionEventDetails Giá Trị Mặc Định: nil |
Lợi Nhuận
()
Mẫu mã
Ghi lại ấn tượng của người dùng
local RecommendationService = game:GetService("RecommendationService")
local function logView(itemId, tracingId)
local detail: RecommendationImpressionEventDetails = {
Duration = 5, -- Người dùng đã xem trong 5 giây
ItemPosition = 1,
DepartureIntent = Enum.RecommendationDepartureIntent.Neutral
}
RecommendationService:LogImpressionEvent(Enum.RecommendationImpressionType.View, itemId, tracingId, detail)
print("Đã ghi lại ấn tượng 'Xem' cho mục: " .. itemId)
end
-- Ví dụ sử dụng (cần một itemId và tracingId hợp lệ từ GenerateItemListAsync)
logView("some-item-id", "some-tracing-id")Log Preference Event
Recommendation Service: Log Preference Event(
preference Type:Enum.RecommendationPreferenceType, target Type:Enum.RecommendationPreferenceTargetType, target Id:string, tracing Id:string, item Id:string
):()
Tham Số
Lợi Nhuận
()
Register Item Async
Recommendation Service: Register Item Async(
Tham Số
registerRecommendationItemsRequest:RegisterRecommendationItemRequest |
Lợi Nhuận
Mẫu mã
Đăng ký một mục mới
local RecommendationService = game:GetService("RecommendationService")
local storage = game:GetService("ReplicatedStorage")
-- Giả sử một RemoteFunction có tên 'RegisterItemRemote' tồn tại trong 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:en-us", "seasonal:summer"},
Attributes = {
{
AssetId = 123,
Description = "video thử nghiệm",
TrimStartTime = 0,
TrimEndTime = 10.5
}
}
}
local success, response = pcall(function()
return RecommendationService:RegisterItemAsync(player, request)
end)
if success and response then
print("Đã đăng ký mục thành công. ItemId: " .. response.ItemId)
return response.ItemId
else
warn("Đăng ký mục thất bại. Lỗi: " .. tostring(response))
return nil
end
endRemove Item Async
Tham Số
Lợi Nhuận
()
Mẫu mã
Xóa một mục
local RecommendationService = game:GetService("RecommendationService")
local function removeItem(itemId)
local success, err = pcall(function()
return RecommendationService:RemoveItemAsync(itemId)
end)
if success then
print("Đã xóa thành công mục: " .. itemId)
else
warn("Không thể xóa mục: " .. itemId .. ". Lỗi: " .. tostring(err))
end
end
removeItem("itemId")Update Item Async
Recommendation Service: Update Item Async(update Recommendation Item Request:UpdateRecommendationItemRequest):()
Tham Số
updateRecommendationItemRequest:UpdateRecommendationItemRequest |
Lợi Nhuận
()
Mẫu mã
Cập nhật một mục
local RecommendationService = game:GetService("RecommendationService")
local function updateItem(itemId)
-- Chỉ bao gồm các trường bạn muốn cập nhật
local request: UpdateRecommendationItemRequest = {
ItemId = itemId,
Visibility = Enum.RecommendationItemVisibility.Private,
-- LƯU Ý: toàn bộ danh sách CustomTags sẽ được thay thế bằng danh sách mới này
CustomTags = {"updated-tag"}
}
local success, err = pcall(function()
return RecommendationService:UpdateItemAsync(request)
end)
if success then
print("Cập nhật thành công mục: " .. itemId)
else
warn("Cập nhật mục thất bại: " .. itemId .. ". Lỗi: " .. tostring(err))
end
end
-- Ví dụ sử dụng
updateItem("some-item-id-to-update")