forked from thelinmichael/spotify-web-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-info-about-current-user.js
52 lines (43 loc) · 2.01 KB
/
get-info-about-current-user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var SpotifyWebApi = require('../');
/**
* This example retrieves information about the 'current' user. The current user is the user that has
* authorized the application to access its data.
*/
/* Retrieve a code as documented here:
* https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow
*
* Codes are given for a set of scopes. For this example, the scopes are user-read-private and user-read-email.
* Scopes are documented here:
* https://developer.spotify.com/spotify-web-api/using-scopes/
*/
var authorizationCode = 'AQAgjS78s64u1axMCBCRA0cViW_ZDDU0pbgENJ_-WpZr3cEO7V5O-JELcEPU6pGLPp08SfO3dnHmu6XJikKqrU8LX9W6J11NyoaetrXtZFW-Y58UGeV69tuyybcNUS2u6eyup1EgzbTEx4LqrP_eCHsc9xHJ0JUzEhi7xcqzQG70roE4WKM_YrlDZO-e7GDRMqunS9RMoSwF_ov-gOMpvy9OMb7O58nZoc3LSEdEwoZPCLU4N4TTJ-IF6YsQRhQkEOJK';
/* Set the credentials given on Spotify's My Applications page.
* https://developer.spotify.com/my-applications
*/
var spotifyApi = new SpotifyWebApi({
clientId : 'fcecfc72172e4cd267473117a17cbd4d',
clientSecret : 'a6338157c9bb5ac9c71924cb2940e1a7',
redirectUri : 'http://www.example.com/callback'
});
// First retrieve an access token
spotifyApi.authorizationCodeGrant(authorizationCode)
.then(function(data) {
console.log('Retrieved access token', data['access_token']);
// Set the access token
spotifyApi.setAccessToken(data['access_token']);
// Use the access token to retrieve information about the user connected to it
return spotifyApi.getMe();
})
.then(function(data) {
// "Retrieved data for Faruk Sahin"
console.log('Retrieved data for ' + data['display_name']);
// "Email is [email protected]"
console.log('Email is ' + data.email);
// "Image URL is http://media.giphy.com/media/Aab07O5PYOmQ/giphy.gif"
console.log('Image URL is ' + data.images[0].url);
// "This user has a premium account"
console.log('This user has a ' + data.product + ' account');
})
.catch(function(err) {
console.log('Something went wrong', err);
});