简体   繁体   中英

Firebase URL Shortener with jQuery Ajax Post?

I'm new to Firebase. I'm trying to make use of Dynamic Links. This is what I have so far...

    var longUrl = 'https://example.com/' + window.location.hash;
    var APIkey  = 'My Web API Key Here';
    var url     = 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=' + APIkey;

    var data = {
        "longDynamicLink": "https://abc123.app.goo.gl/?link=" + longUrl,
        "suffix": {
            "option": "SHORT"
        }
    };

    var request = $.ajax({
        url: url,
        dataType: 'json',
        type: 'post',
        contentType: 'application/json',
        data: JSON.stringify(data),
        processData: false,
        success: function( data, textStatus, jQxhr ){
            console.log(data);
            console.log(textStatus);
            console.log(jQxhr);
        },
        error: function( jqXhr, textStatus, errorThrown ){
            console.log( errorThrown );
        }
    });

And I get a 400 error...

code:400
message:"Your project has not configured Dynamic Links. [https://firebase.google.com/docs/dynamic-links/rest#before_you_begin]"
status:"INVALID_ARGUMENT"

What does it mean by not configured Dynamic Links? Is "abc123" just a placeholder?

Had the same issue- and thats the answer i got from the firebase team:

Take note that to be able to view your Dynamic Link domain you'll have to add an app first. If you're using Firebase Dynamic Link as a substitute to Google Shortener, you can create a sample application (dummy app) for your project to proceed creating a Firebase Dynamic Links. Just enter dummy values for the iOS bundle ID or Android package name (ex: “my.dummy.app”) to continue.

then you'll put the id you'll get from it (eg https://dedfgu.app.goo.gl ) instead of the place holder (abc123.app.goo.gl).

Good luck!

abc123 is a placeholder. You supposed to provide your Firebase Dynamic Links domain instead of abc123 .

For example see here https://firebase.google.com/docs/dynamic-links/ios/create description what is project's Dynamic Links domain. Domain looks like app_code.app.goo.gl , where app_code is unique to each Firebase project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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