1
votes

I'm currently using google scripts to upload an images to an imgur account. However, when I use this URL: https://api.imgur.com/oauth2/authorize?client_id=*clientID*&response_type=token I don't get a valid JSON response. When I paste it directly into the browser I go to the oAuth page. How do I avoid the oauth page and get a valid response when trying to get an access token.

function authorizeTokenGET () {
  url = "https://api.imgur.com/oauth2/authorize?client_id="+clientID+"&response_type=token";
  response = UrlFetchApp.fetch(url);
  console.log(url);
  console.log(JSON.parse(response))
  
}

The error: SyntaxError: Unexpected token < in JSON at position 0

(Yes I did register my application with the anonymous usage without user authorization option)

1

1 Answers

0
votes

What you want to do is actually get the refresh token and use that to generate access tokens, as described in the documentation here https://apidocs.imgur.com/#oauth-20-overview.

  • refresh_token: is used to request new access_tokens. Since access_tokens expire after 1 month, we need a way to request new ones without going through the entire authorization step again. It does not expire.

As it says, once we have a refresh token (which lasts forever), we can use that to get the access token whenever we need them and skip the oauth step.