Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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
Angularjs 如何获取访问令牌&;节点spotify api的刷新令牌&;或流星SpotifyAPI_Angularjs_Token_Spotify_Access Token_Meteor Accounts - Fatal编程技术网

Angularjs 如何获取访问令牌&;节点spotify api的刷新令牌&;或流星SpotifyAPI

Angularjs 如何获取访问令牌&;节点spotify api的刷新令牌&;或流星SpotifyAPI,angularjs,token,spotify,access-token,meteor-accounts,Angularjs,Token,Spotify,Access Token,Meteor Accounts,我正在使用xinranxiao开发Angular Meteor中的一个应用程序:spotify web api包,它是基于&package构建的,用于使用spotify登录 我可以通过创建spotify Web Api提供的客户端Id和客户端机密以及重定向uri(仅http://localhost:3000/_oauth/spotify?close。我有一个页面,我列出了用户的播放列表,它显示了专辑的艺术作品。我将spotify的frame player与上面的专辑/播放列表的链接放在相册插图的

我正在使用xinranxiao开发Angular Meteor中的一个应用程序:spotify web api包,它是基于&package构建的,用于使用spotify登录

我可以通过创建spotify Web Api提供的客户端Id和客户端机密以及重定向uri(仅
http://localhost:3000/_oauth/spotify?close
。我有一个页面,我列出了用户的播放列表,它显示了专辑的艺术作品。我将spotify的frame player与上面的专辑/播放列表的链接放在相册插图的正下方,但有一个
401错误。需要身份验证

我已登录,但仍需要身份验证

如果我在我的chrome浏览器控制台中键入
Meteor.loginWithSpotify()
,我会被取消定义,并且看不到我的访问令牌?如何获取访问令牌并刷新它?我相信这就是它显示我仍然需要身份验证的原因,以及为什么如果我键入
Meteor.loginWithSpotify()
我会得到
未定义的

在我的服务器端Meteor代码中,我有:

ServiceConfiguration.configurations.update(
  { "service": "spotify" },
  {
    $set: {
      "clientId": "000000000000000000000000000000",
      "secret": "000000000000000000000000000000"
    }
  },
  { upsert: true }
)
var options = {
  showDialog: true, // Whether or not to force the user to approve the app again if they’ve already done so.
  requestPermissions: ['user-read-email','playlist-modify-private', 'user-library-read','user-follow-read', 'playlist-read-private','streaming'] // Spotify access scopes.
};

var scopes = ['user-read-email','playlist-modify-private', 'user-library-read','user-follow-read', 'playlist-read-private','streaming']
Accounts.ui.config({'requestPermissions':{'spotify':scopes}})

Meteor.loginWithSpotify(options, function(accessToken) {
  console.log('accessToken is ', accessToken)
});
在我的客户端Meteor方法中,我有一个getUserPlaylists方法,它执行它所说的操作,并且工作正常。下面是checkTokenRefreshed方法,我仍然不确定它是否正在刷新令牌:

Meteor.methods({

  // Get a user's playlists
  getUserPlaylists: function() {
    //Spotify call
    var spotifyApi = new SpotifyWebApi()
    //response object
    var userplaylists = spotifyApi.getUserPlaylists(Meteor.user().profile.id,function(err,data){
      if(err){
        console.log("Retrieval error ", err)
      }
      else{
        console.log("Success, your playlist ", data.body)
      }
    })
    //Need to refresh token
    if(checkTokenRefreshed(userplaylists, spotifyApi)){
      userplaylists = spotifyApi.getUserPlaylists(Meteor.user().profile.id,function(err,data){
        if(err){
          console.log("Retrieval error ", err)
        }
        else{
          console.log("Success, your playlist ", data.body)
        }
      })//end response
    }//end checkTokenRefreshed

    return userplaylists

  }//end getUserPlaylists

})//end Meteor.methods

var checkTokenRefreshed = function(response, api) {
  if (response.error && response.error.statusCode === 401) {
    api.refreshAndUpdateAccessToken();
    return true
  } else {
    return false
  }
}
在我的客户端代码中,我有:

ServiceConfiguration.configurations.update(
  { "service": "spotify" },
  {
    $set: {
      "clientId": "000000000000000000000000000000",
      "secret": "000000000000000000000000000000"
    }
  },
  { upsert: true }
)
var options = {
  showDialog: true, // Whether or not to force the user to approve the app again if they’ve already done so.
  requestPermissions: ['user-read-email','playlist-modify-private', 'user-library-read','user-follow-read', 'playlist-read-private','streaming'] // Spotify access scopes.
};

var scopes = ['user-read-email','playlist-modify-private', 'user-library-read','user-follow-read', 'playlist-read-private','streaming']
Accounts.ui.config({'requestPermissions':{'spotify':scopes}})

Meteor.loginWithSpotify(options, function(accessToken) {
  console.log('accessToken is ', accessToken)
});
客户端代码的最后一个方法应该将我的accessToken打印到控制台,但它会打印未定义的accessToken


我应该提到,我可以使用node/meteor spotify web api spotifyApi.getUserPlaylists()方法访问用户播放列表,但是如果我不能在没有401错误的情况下发布链接,那又有什么好处呢


xinranxiao:meteor spotify api的文档中说2)通过xinranxiao:accounts spotify或直接通过此api(参见)获取oauth access_令牌,了解如何获取)。

我认为最好尝试在未来获得支持。我曾经使用过SpotifyWebAPI,我很乐意提供帮助,但我不知道底层请求是什么样子。你有没有可能创建一个代码失败的小例子,然后发布到某个地方,这样我就可以尝试一下了?嘿,谢谢@JoséM.Pérez。所以我不知道代码的哪一部分失败了,因为我不知道它是如何访问数据的。这里有一个指向我的链接,我相信错误在
MixtapeForum/client/spotifyclientlogin.js
MixtapeForum/server/SpotifyMethods.js
中。在这两个地方,我都应该与访问令牌交互。如果你喜欢的话,我可以试着做一把小提琴,但我用的是MeteorJS,所以我认为它不会是一样的。一把小提琴或meteorpad.com会很棒,我正在处理同样的问题!我认为最好是在未来争取支持。我曾经使用过SpotifyWebAPI,我很乐意提供帮助,但我不知道底层请求是什么样子。你有没有可能创建一个代码失败的小例子,然后发布到某个地方,这样我就可以尝试一下了?嘿,谢谢@JoséM.Pérez。所以我不知道代码的哪一部分失败了,因为我不知道它是如何访问数据的。这里有一个指向我的链接,我相信错误在
MixtapeForum/client/spotifyclientlogin.js
MixtapeForum/server/SpotifyMethods.js
中。在这两个地方,我都应该与访问令牌交互。如果你喜欢的话,我可以试着做一把小提琴,但我用的是MeteorJS,所以我认为它不会是一样的。一把小提琴或meteorpad.com会很棒,我正在处理同样的问题!