Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS:如何防止登录SoundCloud API后每次刷新时丢失会话_Javascript_Soundcloud - Fatal编程技术网

Javascript JS:如何防止登录SoundCloud API后每次刷新时丢失会话

Javascript JS:如何防止登录SoundCloud API后每次刷新时丢失会话,javascript,soundcloud,Javascript,Soundcloud,我正在制作一个仪表板,并从SoundCloudAPI中获取一些信息。我对这个API比较陌生,我已经能够根据列出的每首曲目拉取SoundCloud小部件了。我的问题是每次刷新时,我都会被注销(我想)。即使用户刷新页面,会话是否也可以保持?这就是我现在拥有的: function connectToSoundCloud(){ //INTIALIZE AUTH WITH SC SC.initialize({ client_id: sc_client_i

我正在制作一个仪表板,并从SoundCloudAPI中获取一些信息。我对这个API比较陌生,我已经能够根据列出的每首曲目拉取SoundCloud小部件了。我的问题是每次刷新时,我都会被注销(我想)。即使用户刷新页面,会话是否也可以保持?这就是我现在拥有的:

   function connectToSoundCloud(){
       //INTIALIZE AUTH WITH SC
        SC.initialize({
        client_id: sc_client_id,
        redirect_uri: sc_redirect_uri
     });
        //INITIATE AUTH POPUP
            SC.connect(function() {
  SC.get('/me', function(me) { 

        if (me.username) { 
            document.getElementById('btn-disconnectFromSoundCloud').style.display=""; 
            document.getElementById('btn-connectToSoundCloud').style.display="none"; 
        }

        $.ajax({
            type: "GET",
            url: "http://api.soundcloud.com/tracks.json?client_id="+sc_client_id+"",
            error: function(result, status){
            },
            success: function(result, status){
                        //CODE TO DISPLAY TRACKS HERE
            }
        });
  });
});
    }

感谢您的帮助。干杯。

您有没有安排
jStorage
?从下载它。将jStorage.js文件导入到代码中,就可以开始了<代码> 然后,您可以按如下方式存储已登录的用户:

SC.connect(function() {
SC.get('/me', function(me) { 
    $.jStorage.set('userInfo',me); // store the user to storage
    console.log("Logged in userId: "+ me.id); 
    console.log('Logged in username: '+me.username);
    location.reload(); // reloads the page
    });

});
然后,无论何时,只要想获取有关登录用户的信息,就可以使用:

var loggedInUser=$.jStorage.get('userInfo')

要注销,只需使用

$.jStorage.deleteKey('userInfo'); // delete the logged in user
location.reload(); // reloads the page

这将保存正在发送的用户数据,但这是否也确保他们已登录?还有上传和评论功能吗?