如何在分支深度链接中访问添加的参数

时间:2017-12-14 05:01:17

标签: android json branch.io

这个问题不是this question的重复。我已经尝试过那里提到的解决方案,但没有任何运气。

我已将branch.io深层链接添加到我的应用中。为了测试实现,我创建了一个带参数的链接,如下所述   https://docs.branch.io/pages/apps/android/#test-deep-link

一切正常,但问题是我无法访问json对象中添加的数据,因为json没有包含我之前添加的密钥。我应该得到这样的回复:

    {
  "identity_id": "427469360685348303",
  "link": "https://example.app.link?%24identity_id=427469360685348303",
  "session_id": "429691081177874743",
  "data": {
    "$canonical_identifier": "item/1503684554354.28",
    "$desktop_url": "http://example.com/home",
    "$exp_date": 0,
    "$identity_id": "427469360685348303",
    "$og_description": "My Content Description",
    "$og_image_url": "http://lorempixel.com/200/200/",
    "$og_title": "46D6D28E-0390-40E4-A856-BD74F34D24C8",
    "$publicly_indexable": 1,
    "+click_timestamp": 1503684563,
    "+clicked_branch_link": true,
    "+is_first_session": false,
    "+match_guaranteed": true,
    "custom": "blue",
    "random": "FE848A5B-78F7-42EC-A253-9F795FE91692",
    "added": "1503684554354.33",
    "~campaign": "new launch",
    "~channel": "facebook",
    "~creation_source": 3,
    "~feature": "sharing",
    "~id": 429691043152332059,
    "~referring_link": "https://example.app.link/X7OsnWv9TF",
    "~stage": "new person",
    "~tags": [
      "one",
      "two"
    ]
  }
}

但这是我得到的回应:

{"+non_branch_link":"https:\/\/qr6x.test-app.link\/g5ynWCX7PI","+clicked_branch_link":false,"+is_first_session":false}

这是我的代码:

 Branch branch = Branch.getInstance(context);

    branch.initSession(new Branch.BranchReferralInitListener() {
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            if (error == null) {
                // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
                // params will be empty if no data found
                // ... insert custom logic here ...


                try {
                    Log.e("myapp","no error");
                    Log.e("myapp", referringParams.toString());

                    String pictureID = referringParams.optString("asdasdasdasd", "");
                    if (pictureID.equals("")) {
                        Log.e("myapp","no ID");
                    }
                    else {
                        Log.e("myapp","ID "+pictureID);
                    }
                } catch (Exception e) {
                    System.out.println(" " + e.toString());
                }




            } else {
                Log.i("MyApp", error.getMessage());
            }
        }
    }, intent.getData(), activity);

任何人都可以知道我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

Jackie来自分公司。 + non_branch_link通常在创建分支深层链接时出现错误时发生,或者每当live_key / test_key混淆时(即点击测试链接与使用您的实时密钥的应用程序,或反之亦然)。

您是否可以确认您的登台应用的AndroidManifest.xml中有正确的Branch测试密钥?这是我们在Android应用配置上的documentation

如果您仍然遇到问题,请随时将您的APK文件发送至integrations@branch.io,我们很乐意为您进一步调查。