-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpull_user_data.js
More file actions
28 lines (24 loc) · 848 Bytes
/
pull_user_data.js
File metadata and controls
28 lines (24 loc) · 848 Bytes
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
var SpotifyWebApi = require('spotify-web-api-node');
var mongoose = require('mongoose');
var serverConfig = require('./serverConfig.json');
// Import schemas
var schemas = require('./schemas.js');
// This should be at the top of oauth.js
// -------------------------------------------------
function store_data(songList, event) {
// List of songs from a user
schemas.Event.update({name:event}, {$push:{songNames:songList}}, function(err) {
if (err) throw err;
});
}
exports.pullAttendeeData = function(accessToken, event) {
var spotifyApi = new SpotifyWebApi();
spotifyApi.setAccessToken(accessToken);
spotifyApi.getMyTopTracks(limit=50)
.then(function(data) {
var songList = data.body.items.map(function(item) {return item.id});
store_data(songList, event);
}, function(err) {
throw err;
});
}