简体   繁体   English

如何将Spotify应用程序连接到Facebook Connect?

[英]How do I connect my Spotify App to Facebook Connect?

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. 我正在开发一个Spotify应用程序,并且通过大量的反向工程和从检查器检查javascript对象,一切都进行得很好。 However, I can't seem to manage to get the Facebook connect code working. 但是,我似乎无法设法使Facebook连接代码正常工作。

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. 我尝试过使用Facebook Javascript FB.init() ,然后使用FB.login,但域为sp:// myidentifier,这对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? 最好的方法是,是否有任何内置方法可以执行此操作,因为Spotify首先与Facebook建立了良好的联系?

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. 从今天起,我将无法检查其他应用程序,否则我可能会向正确的方向发展。

I was faster than Stackoverflow this time ;) 这次我比Stackoverflow快;)

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,
    'display=popup',
    'scope=email,read_stream',
    'response_type=token'
    ];

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


        });


    }
}); 

Use the auth module instead. 请改用auth模块。 sp.core is a private object and will not pass the approval stage for submitting an app on App Finder. sp.core是私有对象,不会通过批准阶段在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() { }
});

https://developer.spotify.com/technologies/apps/docs/beta/09321954e7.html https://developer.spotify.com/technologies/apps/docs/beta/09321954e7.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM