向GOOGLE URL Shorteners API发出POST请求

时间:2018-09-07 18:27:18

标签: python api python-requests google-url-shortener

我将api_key放在哪里?

我想添加我的API密钥,但是没有选项或如何做,除了没有API密钥外,我还收到403超出限制错误

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 个答案:

答案 0 :(得分:0)

the docs for the Google URL Shortener service说:

  

从2018年3月30日开始,我们将拒绝对goo.gl URL缩短器的支持。有关详细的时间表和替代方法,请参见this blog post

如果您点击博客文章的链接,则说明了详细信息,但此处的相关部分是:

  

从2018年5月30日开始,只有在今天之前访问过URL Shortener API的项目才能创建短链接。

那么,你能做什么?

Google显然希望您切换到其新的和改进的功能Firebase Dynamic Links

  

要创建新的短链接,我们建议使用FDL API。 FDL短链接将自动检测用户的平台,并根据需要将用户发送到Web或您的应用。

他们提供了migration support

对于那些不想这样做的人,最好的选择就是他们向goo.gl网站的消费者推荐的东西:

  

如果您要创建新的短链接,建议您选择Bitly和Ow.ly等热门服务作为替代。

请注意,BitlyOw.ly都具有API。它们与Goo.gl有点类似-肯定比FDL更近-但不完全相同。