Skip to content

Instantly share code, notes, and snippets.

View thelinmichael's full-sized avatar

Michael Thelin thelinmichael

  • Stockholm, Sweden
View GitHub Profile
@thelinmichael
thelinmichael / remove-tracks-example-async
Last active August 9, 2019 06:35
Spotify API node client - Remove a track using async function
var SpotifyWebApi = require('spotify-web-api-node');
// Set the credentials when making the request
// For testing purposes, you can retrieve an access token from Spotify's Web Console here
// https://developer.spotify.com/console/delete-playlist-tracks
var spotifyApi = new SpotifyWebApi({
accessToken: ''
});
var tracks = [{ uri : "spotify:track:03EuhmMsEHVFI9ytainStU" }]; // track to remove
@thelinmichael
thelinmichael / remove-tracks-example
Created August 9, 2019 06:25
Spotify API node client - Remove a track
var SpotifyWebApi = require('spotify-web-api-node');
// Set the credentials for the request
// For testing purposes, you can retrieve an access token from Spotify's Web Console here
// https://developer.spotify.com/console/delete-playlist-tracks
var spotifyApi = new SpotifyWebApi({
accessToken: ''
});
// Remove a track in the playlist
@thelinmichael
thelinmichael / spotify-apps-api-printing-position
Last active August 29, 2015 14:01
Spotify Apps API 1.x: Printing player positions after changing track
require(["$api/models"], function(models) {
var getPosition = function(callback) {
models.player.load("position")
.done(function(player) {
callback(null, player.position);
})
.fail(function(error) {
callback(error);
});
@thelinmichael
thelinmichael / publish-unpublish-playlists
Last active August 29, 2015 13:58
Publishing and unpublishing playlists using Spotify Apps API 1.x
require(["$api/models", "$api/library#Library"], function(models, Library) {
// Grab an embarrassing playlist that should be secret
var playlist = models.Playlist.fromURI("spotify:user:thelinmichael:playlist:3ktAYNcRHpazJ9qecm3ptn");
// Get the library object for the current user
var library = Library.forCurrentUser();
// Check if the playlist is published or not
playlist.load("published").
@thelinmichael
thelinmichael / spotify-identifier
Created March 26, 2014 21:08
Loading user identifier using Spotify Apps API 1.x
<script type="text/javascript">
require(['$api/models'], function(models) {
models.session.load("user").done(function(session) {
session.user.load("identifier").done(function(user) {
console.log("The identifier is " + user.identifier);
}).fail(function(error) {
console.log("An error occurred", error);
});
});
});
@thelinmichael
thelinmichael / load-user-identifier
Created March 8, 2014 13:05
Spotify Apps API 1.x. Get the current user's identifier.
require(['$api/models'], function(models) {
models.session.load("user").done(function(session) {
session.user.load("identifier").done(function(user) {
console.log(user.identifier);
});
});
});
@thelinmichael
thelinmichael / create-mosaic-for-temporary-playlist
Created March 8, 2014 11:52
Spotify Apps API 1.x. Creating a playable mosaic image for a temporary playlist.
require(['$api/models', '$views/image#Image'], function(models, Image) {
var imageForTempPlaylist = function(playlist) {
var imageURI = "spotify:mosaic:",
promise = new models.Promise();
playlist.tracks.snapshot(0, 4).done(function(snapshot) {
var trackImageURIs = snapshot._meta.map(function(trackMetadata) {
return trackMetadata.image;
});
@thelinmichael
thelinmichael / iterate-over-snapshot
Created March 8, 2014 11:01
Spotify Apps API. Iterate over snapshot.
require(['$api/relations#Relations'], function(Relations) {
var rels = Relations.forCurrentUser();
rels.combinedSubscriptions.snapshot().done(function(snapshot) {
console.log('You have a total of', snapshot.length, 'follower(s).');
console.log('Here are your followings:', snapshot.toArray());
var items = snapshotToArray(snapshot);
console.log("And here are your followings again:", items);
});
});
@thelinmichael
thelinmichael / user-activity
Created February 22, 2014 21:59
Retrieving user activity for another user.
<html>
<head>
<title></title>
<script type="text/javascript">
require(["$api/models", "$api/activity#Feed"], function(models, Feed) {
// Retrieve feed for user
var user = models.User.fromURI("spotify:user:kristin.mv");
@thelinmichael
thelinmichael / get-artist-and-user-relations
Created January 31, 2014 21:00
Spotify Apps API - Get a list of artists and users that a specified user is following
<html>
<head>
</head>
<body>
<script>
require(["$api/models#User", "$api/relations#Relations"], function(User, Relations) {
var username = "kristiankarl";
var relations = Relations.forUser(User.fromURI("spotify:user:" + username));
relations.load("combinedSubscriptions").done(function() {
relations.combinedSubscriptions.snapshot().done(function(snapshot) {