首页 > 解决方案 > Branch.io initSession 返回空的 BranchUniversalObject JSON 和 BranchLinkProperties JSON

问题描述

我正在尝试使用 Unity Branch SDK 向我现有的应用程序添加共享功能。

我使用以下代码创建了短 URL。

BranchUniversalObject universalObject = new BranchUniversalObject();
BranchLinkProperties linkProperties = new BranchLinkProperties();
string deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier;

universalObject.canonicalIdentifier = $"xLeague/{deviceUniqueIdentifier}";
universalObject.canonicalUrl = "http://xleague.games/";
universalObject.title = MetaDataManager.Title;
universalObject.contentDescription = MetaDataManager.Description;
universalObject.imageUrl = MetaDataManager.Image;

linkProperties.controlParams.Add("$desktop_url", "http://xleague.games/xleague-solitaire-share/");
linkProperties.controlParams.Add("$android_url", "http://xleague.games/android");
linkProperties.controlParams.Add("$ios_url", "https://apps.apple.com/us/app/xleague-solitaire/id1480117114");
linkProperties.controlParams.Add("$ipad_url", "https://apps.apple.com/us/app/xleague-solitaire/id1480117114");
linkProperties.controlParams.Add("$match_duration", "2000");
linkProperties.controlParams.Add("$og_title", MetaDataManager.Title);
linkProperties.controlParams.Add("$og_description", MetaDataManager.Description);
linkProperties.controlParams.Add("$og_image_url", MetaDataManager.Image);
linkProperties.controlParams.Add("$deviceID", deviceUniqueIdentifier);

Branch.getShortURL(universalObject, linkProperties, (param, error) =>
{
    if (error != null)
    {
        Debug.LogError("Branch.getShortURL failed: " + error);
    }
    else if (param != null)
    {
        callback(param);
    }
});

我可以从 Unity Branch 获得以下短 URL。

https://xleague.app.link/r7DxT2wkZ5

https://xleague.app.link/4WPwY7jm05

https://xleague.app.link/LFfAOZuo05

https://xleague.app.link/hVR3fr0n05

我使用以下代码检索 BranchUniversalObject 和 BranchLinkProperties。

void Start()
{
    Branch.initSession(CallbackWithBranchUniversalObject);
}

void CallbackWithBranchUniversalObject(BranchUniversalObject buo, BranchLinkProperties linkProps, string error)
{
    if (error != null)
        Debug.Log($"Error : {error}");
    else
    {
        Debug.Log(buo.ToJsonString());
        Debug.Log(linkProps.ToJsonString());
        if (linkProps.controlParams.ContainsKey("$deviceID"))
        {
            string senderDeviceID = linkProps.controlParams["$deviceID"];
            ...
        }
    }
}

如果我在 iPhone 或 Android 上单击共享链接,它会将我重定向到 Appstore 或 Google Play 商店。我可以在 Appstore 和 Google Play Store 上安装该应用程序。但是当我打开应用程序时,initSession 返回空的 BranchUniversalObject JSON 和 BranchLinkProperties JSON。

BranchUniversalObject JSON

{
  "$canonical_identifier": "",
  "$canonical_url": "",
  "$og_title": "",
  "$og_description": "",
  "$og_image_url": "",
  "$publicly_indexable": "0",
  "$locally_indexable": "0",
  "$exp_date": "69425078400000",
  "$keywords": [],
  "metadata": "{}"
}

分支链接属性 JSON

{
  "~tags": [],
  "~feature": "",
  "~alias": "",
  "~channel": "",
  "~stage": "",
  "~duration": "0",
  "control_params": {}
}

让我更困惑的是,initSession 有时会按预期返回正确的 BranchUniversalObject JSON 和 BranchLinkProperties JSON。我猜我创建的 Branch Short URL 仅适用于第一次点击。如果您能帮助我,我将不胜感激。

标签: deep-linkingbranch.io

解决方案


一个分店在这里 -

请仔细检查您的集成,如此所述。对于进一步的故障排除,您也可以按照此处所述进行操作。如果在您单击后台链接时发生这种情况,请确保您遵循应用内链接指南并确保按照建议实施 onNewIntent 。

请注意,单击链接时,它应该只打开具有 initSession() 方法的 Activity。另外请不要公开分享您的分支密钥。


推荐阅读