Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Any ideas why?

like image 588
Kento Nishi Avatar asked Jul 19 '26 11:07

Kento Nishi


1 Answers

I haven't ever tried this but, ...

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");
    }
});
like image 181
Ronnie Royston Avatar answered Jul 21 '26 01:07

Ronnie Royston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!