Python 向GOOGLE URL Shorteners API发出POST请求

Python 向GOOGLE URL Shorteners API发出POST请求,python,api,python-requests,google-url-shortener,Python,Api,Python Requests,Google Url Shortener,我应该把我的api_密钥放在哪里 我想添加我的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': 'applicatio

我应该把我的api_密钥放在哪里

我想添加我的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)
比如说:

从2018年3月30日开始,我们将拒绝对goo.gl URL shortener的支持。有关详细的时间表和备选方案,请参见

如果你点击博客文章的链接,它会解释细节,但这里的相关部分是:

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

那么,你能做什么

谷歌显然更希望你切换到他们新的和改进的功能:

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

而且他们提供

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

如果您希望创建新的短链接,我们建议您选择热门服务,如Bitly和Ow.ly


请注意,和都有API。它们有点类似于Goo.gl,当然比FDL更接近,但不完全相同。

我很确定这个API已经死了,除了几个月的长期用户过渡期。我复制了curl命令并将其转换为代码