Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase "long link is not parsable"

I want to shorten a longLink with firebase and the REST API but I get the following response and I don't know what is wrong:

Response:

   {
        "error": {
            "code": 400,
            "message": "Long link is not parsable: https://www.google.de [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]",
            "status": "INVALID_ARGUMENT"
        }
    }

And this is how I do it:

The Request: https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=(hereismyapikey)

the Body lookes like this:

{
   "longDynamicLink": "https://www.google.de",
   "suffix": {
    "option": "SHORT"
  }
}

I tried first with the real URL I want to shorten. Same error. Than with google and with and without the http(s). I'm out of options and hope somebody sees what I did wrong here.

EDIT: Full Postman request:

    "item": [
            {
                "name": "shortLinks",
                "request": {
                    "method": "POST",
                    "header": [
                        {
                            "key": "Content-Type",
                            "value": "application/json"
                        }
                    ],
                    "body": {
                        "mode": "raw",
                        "raw": "{\r\n   \"longDynamicLink\": \"www.google.de\",\r\n   \"suffix\": {\r\n    \"option\": \"SHORT\"\r\n  }\r\n}"
                    },
                    "url": {
                        "raw": "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=xxx",
                        "protocol": "https",
                        "host": [
                            "firebasedynamiclinks",
                            "googleapis",
                            "com"
                        ],
                        "path": [
                            "v1",
                            "shortLinks"
                        ],
                        "query": [
                            {
                                "key": "key",
                                "value": "xxx"
                            }
                        ]
                    }
                },
                "response": []
        }
    ]
like image 766
breezertwo Avatar asked Jun 11 '18 12:06

breezertwo


2 Answers

You are using the simple method for creating dynamic link which is roughly equals to the manual creation of dynamic link : https://firebase.google.com/docs/dynamic-links/create-manually

In the docs if you see the link passed in example carefully you will see the pattern as below:

https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]

So you should format the input link according to this or create using the parameters which has very good breakdown of parameters in json:

https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters

Here is the api reference for firebase dynamic link creation from parameters:

https://firebase.google.com/docs/reference/dynamic-links/link-shortener#parameters

like image 97
Umar Hussain Avatar answered Oct 26 '22 23:10

Umar Hussain


I find the JSON parameter method is easier.

var body = {
  "dynamicLinkInfo": {
    "dynamicLinkDomain": "yourcustom.page.link",
    "link": fileUrl
  },
  "suffix": {
    "option": "SHORT"
  }
};

Then if you're using Node. The node-fetch package REST call would work like:

  var fetchFileUrl = fetch(YOUR_SHORTLINK_URL, { 
      method: 'POST',
      body: JSON.stringify(body),
      headers: { 'Content-Type': 'application/json' },
  }).then(function(response){
    return response.json();
  });
like image 30
Ronnie Royston Avatar answered Oct 27 '22 01:10

Ronnie Royston