简体   繁体   English

使用JavaScript创建Firebase动态链接

[英]Firebase Dynamic Link Creation With JavaScript

var object={
"longDynamicLink": "https://[APP_NAME].page.link/?link=[LINK_HERE]",
    "suffix":{
        "option":"SHORT"
    }
}
$.ajax({
  url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=[KEY_HERE]',
  type: 'POST',
  dataType: "json",
  data: object,
  success: function(response, textStatus, jqXHR) {
    alert(response.shortLink);
  },
  error: function(jqXHR, textStatus, errorThrown){
    alert(textStatus, errorThrown);
  }
});

The above code works if the "suffix" is deleted from the request. 如果从请求中删除“后缀”,则上述代码有效。 That makes an "UNGUESSABLE" url, but I want a short URL. 这是一个“无法使用”的网址,但我想要一个简短的网址。 As stated in the documentation at https://firebase.google.com/docs/dynamic-links/rest?authuser=0 I added the suffix option parameter, but it results with a 400 response. 正如https://firebase.google.com/docs/dynamic-links/rest?authuser=0上的文档中所述,我添加了后缀选项参数,但结果是400响应。 Any ideas why? 有什么想法吗?

I haven't ever tried this but, ... 我没有尝试过这个,但......

POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=api_key POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=api_key

var params = {
   "longDynamicLink": "https://example.page.link/?link=http://www.example.com/&apn=com.example.android&ibi=com.example.ios",
   "suffix": {
     "option": "SHORT"
   }
}

$.ajax({
    url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=[KEY_HERE]',
    type: 'POST',
    data: jQuery.param(params) ,
    contentType: "application/json",
    success: function (response) {
        alert(response.status);
    },
    error: function () {
        alert("error");
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM