Google URL Shortener API Issues

234 Views Asked by At

I have been able to successfully shorten my custom URLs using https://goo.gl/ howsoever, using their API seems to be presenting many challenges. One being that it fails for non-https URLs. Another one is that it works fine for the code below when longUrl is https://www.yahoo.com/ but fails if it's https://yahoo.com. Notice the missing trailing slash.

    {
      url: `https://www.googleapis.com/urlshortener/v1/url?key=${GOOGLE_URL_SHORTENER_KEY}`,
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ longUrl }),
    }

My custom URLs that have query parameters work fine using the browser but fail with the error below which is the same error I receive when using a longUrl value of https://www.yahoo.com.

  {
  "error": {
    "errors": [
    {
      "domain": "global",
      "reason": "forbidden",
      "message": "Forbidden"
    }
    ],
    "code": 403,
    "message": "Forbidden"
  }
  }

Would anyone know how to get around these API limitations and is there good documentation for the limitations imposed by this API?

0

There are 0 best solutions below