【问题标题】:Firebase Dynamic Link Creation With JavaScript使用 JavaScript 创建 Firebase 动态链接
【发布时间】:2018-06-14 22:29:10
【问题描述】:
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);
  }
});

如果从请求中删除“后缀”,则上述代码有效。这会产生一个“不可猜测”的网址,但我想要一个短网址。正如https://firebase.google.com/docs/dynamic-links/rest?authuser=0 的文档中所述,我添加了 suffix 选项参数,但结果是 400 响应。任何想法为什么?

【问题讨论】:

    标签: javascript jquery ajax firebase firebase-dynamic-links


    【解决方案1】:

    我从来没有尝试过,但是,...

    发布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");
        }
    });
    

    【讨论】:

    • 我认为你是对的,罗恩。我尝试了一个带有和不带有 contentType 的 cURL 请求,当我关闭它时,我得到了 400 响应。
    • @JenPerson 对。 The documentation 肯定指定了Content-Type: application/json
    • 非常感谢!我每次都在学习一点 Firebase,像你这样的人帮助很大......谢谢!
    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多