Understanding Oauth2 with spotify

Viewed 226

I followed this tutorial word for word to make a connector between data studio and spotify, but when I go to publish via manifest, I get the following error:

"Client ID is required.

:45 validate_:42 :298 get3PAuthorizationUrls:79"

I've gone through the entire documentation on both sides and it seems like everything should be working. I've refreshed the secret a few times and have triple checked all both the id and the key to make sure it was correct. Here is what my .gs file looks like:

    var oauth = {};

/** @const */
oauth.OAUTH_CLIENT_ID = '53cc7cad362f4ceb9a852c764e4755a5';

/** @const */
oauth.OAUTH_CLIENT_SECRET = 'f5ae9d207a0c4b389175a92a0629b97d';

/**
 * This builds an OAuth2 service for connecting to Spotify
 * More info here: https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorizaton-code-flow
 *
 * @return {OAuth2Service}
 */
function getOAuthService() {
  // This is where we pull out the "client id" and "client secret" from the
  // Script Properties.
  var scriptProps = PropertiesService.getScriptProperties();
  var clientId = scriptProps.getProperty(oauth.OAUTH_CLIENT_ID);
  var clientSecret = scriptProps.getProperty(oauth.OAUTH_CLIENT_SECRET);
  return OAuth2.createService('spotify')
    .setAuthorizationBaseUrl('https://accounts.spotify.com/authorize')
    .setTokenUrl('https://accounts.spotify.com/api/token')
    .setClientId(clientId)
    .setClientSecret(clientSecret)
    .setPropertyStore(PropertiesService.getUserProperties())
    .setScope('user-read-recently-played')
    .setCallbackFunction('authCallback');
}

/**
 * The callback that is invoked after a successful or failed authentication
 * attempt.
 *
 * @param {object} request
 * @return {OAuth2Service}
 */
function authCallback(request) {
  console.log(request);
  var authorized = getOAuthService().handleCallback(request);
  if (authorized) {
    return HtmlService.createHtmlOutput('Success! You can close this tab.');
  } else {
    return HtmlService.createHtmlOutput('Denied. You can close this tab');
  }
}

/**
 * @return {boolean} `true` if the user has successfully authenticated and false
 * otherwise.
 */
function isAuthValid() {
  var service = getOAuthService();
  if (service == null) {
    return false;
  }
  return service.hasAccess();
}

/**
 * Resets the OAuth2 service. This will allow the user to reauthenticate with
 * the external OAuth2 provider.
 */
function resetAuth() {
  var service = getOAuthService();
  service.reset();
}

/**
 * Used as a part of the OAuth2 flow.
 *
 * @return {string} The authorization url if service is defined.
 */
function get3PAuthorizationUrls() {
  var service = getOAuthService();
  if (service == null) {
    return '';
  }
  return service.getAuthorizationUrl();
}
0 Answers
Related