Recommendation Service
概要
方法
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リファレンス
方法
Generate Item List Async
Recommendation Service: Generate Item List Async(generate Recommendation Item List Request: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)
if success then
print("生成された推奨ページ:", recommendationPages)
else
warn("推奨の生成に失敗しました:", recommendationPages)
endGet Recommendation Item Async
パラメータ
戻り値
コードサンプル
単一の推薦アイテムを取得する
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(" カスタムタグ: ")
for _, customTag in ipairs(item.CustomTags) do
print(" " .. customTag)
end
end
else
warn("アイテムの取得に失敗しました: " .. itemId .. ". エラー: " .. tostring(item))
end
end
-- 使用例 (有効な itemId が必要です)
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: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
-- 使用例 (GenerateItemListAsync からの有効な itemId と tracingId が必要です)
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: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("アイテムの 'View' インプレッションを記録しました: " .. itemId)
end
-- 使用例 (GenerateItemListAsyncからの有効なitemIdとtracingIdが必要です)
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
):()
パラメータ
戻り値
()
Register Item Async
Recommendation Service: Register Item Async(
パラメータ
戻り値
コードサンプル
新しいアイテムを登録する
local RecommendationService = game:GetService("RecommendationService")
local storage = game:GetService("ReplicatedStorage")
-- ReplicatedStorageに'RegisterItemRemote'という名前のRemoteFunctionが存在すると仮定します
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 = "テストビデオ",
TrimStartTime = 0,
TrimEndTime = 10.5
}
}
}
local success, response = pcall(function()
return RecommendationService:RegisterItemAsync(player, request)
end)
if success and response then
print("アイテムの登録に成功しました。ItemId: " .. response.ItemId)
return response.ItemId
else
warn("アイテムの登録に失敗しました。エラー: " .. tostring(response))
return nil
end
endRemove Item Async
パラメータ
戻り値
()
コードサンプル
アイテムを削除する
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
end
removeItem("itemId")Update Item Async
パラメータ
戻り値
()
コードサンプル
アイテムを更新する
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")