Home > Net >  Connecting Spotify API with Google Sheets
Connecting Spotify API with Google Sheets

Time:12-01

I am trying to find a more stable way to extract Spotify Data into Google Sheets. I need a variety of data, such as (playlist followers/likes, artist followers, and monthly listeners.

Right now I have a way to do all of that. Using importXML and JSON. For reference - FetchingURL Using JSON on Google Sheets v2

I want to use the Spotify API as a more reliable way to get these numbers. However, I am very stuck on how to even start. I have been looking at this website - https://developer.spotify.com/documentation/web-api/reference/#/ and I'm just not sure what to even do.

Any guidance or reference links would be very much appreciated!

Thanks, Robert

CodePudding user response:

You may start with knowing the general guides for Authorization with Spotify Web API as referenced here.

A Web Application is needed for this since most of the information you need to pull from Spotify API (e.g playlist followers/likes, artist followers, and monthly listeners.) is not a publicly available information for the base request URI.

Here is a sample of Client Credentials OAuth flow:

var request = require('request'); // "Request" library

var client_id = 'CLIENT_ID'; // Your client id
var client_secret = 'CLIENT_SECRET'; // Your secret

// your application requests authorization
var authOptions = {
  url: 'https://accounts.spotify.com/api/token',
  headers: {
    'Authorization': 'Basic '   (new Buffer(client_id   ':'   client_secret).toString('base64'))
  },
  form: {
    grant_type: 'client_credentials'
  },
  json: true
};

request.post(authOptions, function(error, response, body) {
  if (!error && response.statusCode === 200) {

    // use the access token to access the Spotify Web API
    var token = body.access_token;
    var options = {
      url: 'https://api.spotify.com/v1/users/jmperezperez',
      headers: {
        'Authorization': 'Bearer '   token
      },
      json: true
    };
    request.get(options, function(error, response, body) {
      console.log(body);
    });
  }
});

You may login to your Spotify Developer Dashboard here to generate your client ID and client secret upon creating an application environment for the needed authentication flow. You may check this Web API tutorial quickstart from Spotify for Developers

References:

https://github.com/spotify/web-api-auth-examples/blob/master/client_credentials/app.js https://developer.spotify.com/documentation/general/guides/authorization/code-flow/ https://developer.spotify.com/documentation/web-api/quick-start/

  • Related