Platform.Core.AsyncInitialize(appID)
Platform.Entitlements.IsUserEntitledToApplication().OnComplete(callbackMethod);
void callbackMethod (Message msg)
{
if (!msg.IsError)
{
// Entitlement check passed
}
else
{
// Entitlement check failed. Quit app
}
}
AsyncInitialize() 而非 Initialize()。这很重要,因为 AsyncInitialize() 不会阻止初始化代码,从而使您的应用程序加载速度更快。此外,如果初始化失败,AsyncInitialize() 在 Android 上不会抛出异常。AsyncInitialize() 时传入明确 AppId 参数。对于移动开发者:如果您需要在 Unity 编辑器中运行移动应用,必须在 OculusPlatformSettings 中提供 Meta 登录凭证(用户名/密码)。仅设置应用编号是不够的。using UnityEngine;
using Oculus.Platform;
public class AppEntitlementCheck : MonoBehaviour
{
void Awake()
{
try
{
Core.AsyncInitialize().OnComplete(InitializeCallback);
}
catch (UnityException e)
{
Debug.LogErrorFormat("Platform failed to initialize due to exception: %s.", e.Message);
UnityEngine.Application.Quit();
}
}
void InitializeCallback(Message msg)
{
if (msg.IsError)
{
var err = msg.GetError();
Debug.LogErrorFormat("Platform failed to initialize due to exception: %s.", err.ToString());
UnityEngine.Application.Quit();
}
else
{
Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCallback);
}
}
void EntitlementCallback(Message msg)
{
if (msg.IsError)
{
// Implements a default behavior for an entitlement check failure -- log the failure and exit the app.
// Going into a limited demo mode, or displaying an error, is also valid.
var err = msg.GetError();
Debug.LogErrorFormat("Entitlement check failed: %s.", err.ToString());
UnityEngine.Application.Quit();
}
else
{
Debug.Log("You are entitled to use this app.");
}
}
}

POST https://graph.oculus.com/$APP_ID/verify_entitlement
| 参数 | 必要或非必要 | 描述 | 类型 | 示例 |
|---|---|---|---|---|
access_token | 必要 | 包含 OC|$APP_ID |$APP_SECRET 或用户访问口令的 Bearer 口令 | 字符串 | “OC|1234|456789” |
user_id | 必要 | 您想看到购买的用户的用户编号 | 字符串 | “123456789” |
curl -d "access_token=OC|$APP_ID|$APP_SECRET" -d "user_id=$USER_ID" https://graph.oculus.com/$APP_ID/verify_entitlement
{"success":true,"grant_time":1744148687}
| 字段 | 定义 | 类型 |
|---|---|---|
success | 定义用户是否拥有商品的所有权。 | 布尔值 |
grant_time | 用户获得该商品权利的时间 (Unix 时间戳)。 | 数字 |

