Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google URL Shortener API 403 forbidden

I've been exploring google APIs lately and have been playing around with their URL shortening API. I am authenticating using oAuth and have that part down pat. I have managed to successfully use the get and list functions of the API but am having problems making the insert function work.

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.

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.

My oAuth authentication scope:

https://www.googleapis.com/auth/urlshortener
like image 708
Em Eldar Avatar asked Nov 07 '22 04:11

Em Eldar


1 Answers

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.

like image 136
Em Eldar Avatar answered Nov 14 '22 01:11

Em Eldar