简体   繁体   English

Google URL Shortener API 403禁止使用

[英]Google URL Shortener API 403 forbidden

I've been exploring google APIs lately and have been playing around with their URL shortening API. 我最近一直在探索谷歌API,并一直在玩他们的URL缩短API。 I am authenticating using oAuth and have that part down pat. 我正在使用oAuth进行身份验证,并将该部分记录下来。 I have managed to successfully use the get and list functions of the API but am having problems making the insert function work. 我成功地使用了API的get和list函数,但是在使插入函数工作时遇到了问题。

const {google} = require('googleapis');

const urlshortener = google.urlshortener({
    version: 'v1',
    auth: auth
});

async function insert(lengthened) {
    return await urlshortener.url.insert({
        requestBody: {
            longUrl: lengthened
        },
        fields: 'id'
    });
}

Where in this case auth is simply an already authenticated google oauth client that gets passed in from another file. 在这种情况下,auth只是一个已经过身份验证的google oauth客户端,它从另一个文件传入。

Curiously, when I try to call this function I get the following error: 奇怪的是,当我尝试调用此函数时,我收到以下错误:

[ { domain: 'global', reason: 'forbidden', message: 'Forbidden' } ] 

I have scanned through the rest of the response and have not found any additional info. 我已经扫描了其余的响应,但没有找到任何其他信息。 This is strange to me because the other two functions work, I am using oAuth so there should be no problems with API key limiting, and both of the other two API methods work. 这对我来说很奇怪,因为其他两个函数都有效,我正在使用oAuth,因此API密钥限制应该没有问题,并且其他两个API方法都有效。

My oAuth authentication scope: 我的oAuth认证范围:

https://www.googleapis.com/auth/urlshortener

As pointed out in the comments on the original question. 正如对原始问题的评论中所指出的那样。 Google is discontinuing support for their URL shortener. 谷歌正在停止支持他们的网址缩短程序。 This is why retrieving data using this library is possible while creating a new shortened URL is not. 这就是为什么在创建新的缩短URL时可以使用此库检索数据的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM