Take the 2-minute tour ×

I am developing a Spotify App and everything goes very well with a lot of reverse engineering and inspecting the javascript objects from the inspector. However, I can't seem to manage to get the Facebook connect code working.

I have tried using the Facebook Javascript FB.init() and then FB.login but the domain is sp://myidentifier which isn't a valid domain for Facebook.

I see that other apps have managed to get this working so I am sure it works. The best way would be if there were any built in methods for doing this since Spotify is well connected to Facebook to start with?

I really appreciate any help I can get. From today I can't inspect any other apps than my own which otherwise could have put me in the right direction.

share|improve this question
I just got a comment from Spotify: "I can't find this in the docs, but try something like:" sp.core.showAuthDialog(auth_url, close_url, callbacks) –  Christian Landgren Dec 13 '11 at 11:22
add comment

2 Answers

up vote 5 down vote accepted

Use the auth module instead. sp.core is a private object and will not pass the approval stage for submitting an app on App Finder.

var sp = getSpotifyApi(1);
var auth = sp.require('sp://import/scripts/api/auth');

auth.authenticateWithFacebook('MY_APP_ID', ['user_about_me', 'user_checkins'], {

    onSuccess : function(accessToken, ttl) {
        console.log("Success! Here's the access token: " + accessToken);

    onFailure : function(error) {
        console.log("Authentication failed with error: " + error);

    onComplete : function() { }


share|improve this answer
Sorry, my Spotify version ( can't find the auth module. error: Failed to read "sp://import/scripts/api/auth.js" –  Christian Landgren Jan 15 '12 at 13:25
I found this link from another thread asking the same question: developer.spotify.com/blog/archives/2012/01/12/… –  Christian Landgren Jan 15 '12 at 13:58
add comment

I was faster than Stackoverflow this time ;)

This is the code I ended up with:

var appID = "1234567890";
var path = 'https://www.facebook.com/dialog/oauth?';
var successUrl = "https://www.facebook.com/connect/login_success.html";

var queryParams = [
    'client_id=' + appID,
    'redirect_uri=' + successUrl,

var query = queryParams.join('&');
var url = path + query;         

sp.core.showAuthDialog(url, successUrl, {                   
    onSuccess : function(response) {
        console.log('success', response);

        // response contains access token in hashstring
        var queryPart = response.split("#")[1];
        var queryStrings = queryPart.split("&");
        accessToken = queryStrings[0].split('=')[1];

        // we will use the token to get the rest of the user data                                   
        $.getJSON('https://graph.facebook.com/me?access_token=' + accessToken + '&callback=?', function(facebookUser){
            console.log('logged in user: ', facebookUser);                          

            // TODO: add logic to handle the user here


share|improve this answer
How did you figure this out? I don't see any of the sp.core functions documented in the JavaScript API reference: developer.spotify.com/download/spotify-apps-api/reference –  John McCann Jan 1 '12 at 22:07
I got the tip from someone on Spotify to use the sp.core.showAuthDialog and then I used the Inspector console to figure out the rest. Now I got an official answer and updated documentation below so it is probably best to use it, however it doesn't seem to work just yet.. –  Christian Landgren Jan 15 '12 at 13:30
Use @pompas official solution below, it works like a charm. –  Christian Landgren Jan 28 '12 at 9:49
add comment

protected by Community Mar 30 '13 at 19:36

