5

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
Em Eldar
  • 686
  • 1
  • 8
  • 25
  • 1
    Starting March 30, 2018, Google will be turning down support for goo.gl URL shortener. They removed the support in the library as well (https://github.com/google/google-api-nodejs-client/pull/1284). – Boaz Aug 28 '18 at 08:46
  • Thank you! This explains everything – Em Eldar Aug 28 '18 at 20:53

1 Answers1

1

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.

Em Eldar
  • 686
  • 1
  • 8
  • 25