在c#中使用HTTP API的Branch.io链接

时间:2016-05-20 18:47:32

标签: c# dotnet-httpclient branch.io

我正在尝试在我们的网页中通过HTTP API调用创建链接,但是当我尝试创建链接时。 HttpClient响应始终为false。我不确定为什么,但我指定了所有必要的参数

const string BranchIOUrl = "https://api.branch.io/v1/url";

            IDictionary<string, object> branchParams = new Dictionary<string, object>();
            IDictionary<string, string> dataParams = new Dictionary<string, string>();

            branchParams["$branch_key"] = "our branch key";
            branchParams["channel"] = "mobile_web";
            branchParams["feature"] = "create_link";                

            dataParams["$ios_deeplink_path"] = "value here";                                        
            dataParams["$user_profile"] = "7890";
            dataParams["$desktop_url"] = "our app link on appstore";

            branchParams["data"] = dataParams;

            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(BranchIOUrl);

            //Add an accept header for JSon format.
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            // List data response.
            HttpResponseMessage response = await client.PostAsJsonAsync(BranchIOUrl, Newtonsoft.Json.JsonConvert.SerializeObject(branchParams));

1 个答案:

答案 0 :(得分:4)

来自Branch.io的Alex:

看起来问题在于这一行:

branchParams["$branch_key"] = "our branch key";

branch_key参数实际上是指定的没有 $字符(我知道,它有点混淆了什么属于哪里)。如果将其替换为:

branchParams["branch_key"] = "our branch key";

你应该好好去!