Klasa silnika
RecommendationService
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
Podsumowanie
Metody
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):() |
Materiały referencyjne dotyczące interfejsów API
Metody
GenerateItemListAsync
RecommendationService:GenerateItemListAsync(generateRecommendationItemListRequest:Dictionary):RecommendationPages
Parametry
Zwroty
Przykłady kodu
Generuj listę zalecanych przedmiotów
local RecommendationService = game:GetService("RecommendationService")
-- Zdefiniuj żądanie do generowania listy rekomendacji
local request: GenerateRecommendationItemListRequest = {
ConfigName = "MaximizeEngagement",
LocationId = "Lobby",
PageSize = 10
-- UWAGA: Usuń komentarz i ustaw CustomContexts.UserId dla skryptu serwera.
-- Nie ma potrzeby ustawiać dla skryptu lokalnego.
-- CustomContexts = {
-- ["UserId"] = tostring(player.UserId),
-- }
}
-- Wywołaj GenerateItemListAsync, aby uzyskać strony rekomendacji
local success, recommendationPages = pcall(function()
return RecommendationService:GenerateItemListAsync(request)
end)GetRecommendationItemAsync
Parametry
Zwroty
Przykłady kodu
Uzyskaj pojedynczy element rekomendacji
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("Pomyślnie pobrano element: " .. item.ItemId)
print(" ReferenceId: " .. item.ReferenceId)
-- TracingId będzie pusty podczas pobierania pojedynczego elementu bezpośrednio
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("Nie udało się pobrać elementu: " .. itemId .. ". Błąd: " .. tostring(item))
end
end
-- Przykład użycia (wymaga ważnego itemId)
-- getItem("some-item-id")LogActionEvent
RecommendationService:LogActionEvent(
actionType:Enum.RecommendationActionType, itemId:string, tracingId:string, actionEventDetails:Dictionary
):()
Parametry
| Wartość domyślna: "nil" |
Zwroty
()
Przykłady kodu
Rejestrowanie akcji użytkownika
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("Zarejestrowano akcję 'Like' dla przedmiotu: " .. itemId)
end
-- Przykład użycia (wymaga ważnego itemId i tracingId z GenerateItemListAsync)
-- logLike("item-id", "tracing-id")LogImpressionEvent
RecommendationService:LogImpressionEvent(
impressionType:Enum.RecommendationImpressionType, itemId:string, tracingId:string, impressionEventDetails:Dictionary
):()
Parametry
| Wartość domyślna: "nil" |
Zwroty
()
Przykłady kodu
Zaloguj wrażenie użytkownika
local RecommendationService = game:GetService("RecommendationService")
local function logView(itemId, tracingId)
local detail: RecommendationImpressionEventDetails = {
Duration = 5, -- Użytkownik przeglądał przez 5 sekund
ItemPosition = 1,
DepartureIntent = Enum.RecommendationDepartureIntent.Neutral
}
RecommendationService:LogImpressionEvent(Enum.RecommendationImpressionType.View, itemId, tracingId, detail)
print("Zalogowano wrażenie 'Widok' dla przedmiotu: " .. itemId)
end
-- Przykład użycia (wymaga ważnego itemId i tracingId z GenerateItemListAsync)
-- logView("some-item-id", "some-tracing-id")LogPreferenceEvent
RecommendationService:LogPreferenceEvent(
preferenceType:Enum.RecommendationPreferenceType, targetType:Enum.RecommendationPreferenceTargetType, targetId:string, tracingId:string, itemId:string
):()
Parametry
Zwroty
()
RegisterItemAsync
RecommendationService:RegisterItemAsync(
Parametry
Zwroty
Przykłady kodu
Zarejestruj nowy przedmiot
local RecommendationService = game:GetService("RecommendationService")
local storage = game:GetService("ReplicatedStorage")
-- Załóżmy, że w ReplicatedStorage istnieje RemoteFunction o nazwie 'RegisterItemRemote'
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:pl-pl", "seasonal:summer"},
Attributes = {
{
AssetId = 123,
Description = "film testowy",
TrimStartTime = 0,
TrimEndTime = 10.5
}
}
}
local success, response = pcall(function()
return RecommendationService:RegisterItemAsync(player, request)
end)
if success and response then
print("Pomyślnie zarejestrowano przedmiot. ItemId: " .. response.ItemId)
return response.ItemId
else
warn("Nie udało się zarejestrować przedmiotu. Błąd: " .. tostring(response))
return nil
end
endRemoveItemAsync
Parametry
Zwroty
()
Przykłady kodu
Usuń element
local RecommendationService = game:GetService("RecommendationService")
local function removeItem(itemId)
local success, err = pcall(function()
return RecommendationService:RemoveItemAsync(itemId)
end)
if success then
print("Pomyślnie usunięto element: " .. itemId)
else
warn("Nie udało się usunąć elementu: " .. itemId .. ". Błąd: " .. tostring(err))
end
endUpdateItemAsync
Parametry
Zwroty
()
Przykłady kodu
Zaktualizuj element
local RecommendationService = game:GetService("RecommendationService")
local function updateItem(itemId)
-- Uwzględnij tylko te pola, które chcesz zaktualizować
local request: UpdateRecommendationItemRequest = {
ItemId = itemId,
Visibility = Enum.RecommendationItemVisibility.Private,
-- UWAGA: Cała lista CustomTags zostanie zastąpiona tą nową listą
CustomTags = {"updated-tag"}
}
local success, err = pcall(function()
return RecommendationService:UpdateItemAsync(request)
end)
if success then
print("Pomyślnie zaktualizowano element: " .. itemId)
else
warn("Nie udało się zaktualizować elementu: " .. itemId .. ". Błąd: " .. tostring(err))
end
end
-- Przykład użycia
-- updateItem("some-item-id-to-update")