Making a POST request to GOOGLE URL Shorteners API

833 Views Asked by At

Where do I put my api_key ?

I want to add my API KEY but there is no option for it or how do I do it ,apart from it without the API key I am getting 403 Limit exceeded error

import requests
import json
url="https://in.yahoo.com/?p=us"
post_url = 'https://www.googleapis.com/urlshortener/v1/url'
payload = {'longUrl': url}
headers = {'content-type': 'application/json'}
r = requests.post(post_url, data=json.dumps(payload), headers=headers)
print (r.text)
1

There are 1 best solutions below

0
abarnert On

As the docs for the Google URL Shortener service say:

Starting March 30, 2018, we will be turning down support for goo.gl URL shortener. Please see this blog post for detailed timelines and alternatives.

If you follow the link to the blog post, it explains the details, but the relevant part here is:

Starting May 30, 2018, only projects that have accessed URL Shortener APIs before today can create short links.

So, what can you do?

Google obviously would prefer you to switch to their new and improved feature, Firebase Dynamic Links:

To create new short links, we recommend FDL APIs. FDL short links will automatically detect the user's platform and send the user to either the web or your app, as appropriate.

And they provide migration support.

For people who don't want to, or can't, do that, the best option is the same thing they recommend for consumers of the goo.gl website:

If you are looking to create new short links, we recommend you check out popular services like Bitly and Ow.ly as an alternative.

Notice that Bitly and Ow.ly both have APIs. They're somewhat similar to Goo.gl's—certainly closer than FDL—but not identical.