隐式授予流程上的错误使Spotify API出错。角度

时间:2019-05-02 15:02:45

标签: angular api authentication service spotify

因此,我正在尝试实现Spotify API的隐式授予流,但是我遇到了一些CORS错误,我找到了这段代码,但是我得到了一些打字稿错误。我是angular和Typescript的新手,所以希望能提供一些帮助。这是我服务中的代码。

    getTokenFromAPI() {
// Get the hash of the url
const hash = window.location.hash
.substring(1)
.split('&')
.reduce(function (initial, item) {
  if (item) {
    var parts = item.split('=');
    initial[parts[0]] = decodeURIComponent(parts[1]);
  }
  return initial;
}, {});
window.location.hash = '';

// Set token
let _token = hash.access_token;

const authEndpoint = 'https://accounts.spotify.com/authorize';

// Replace with your app's client ID, redirect URI and desired scopes
const clientId = this.clientId;
const redirectUri = 'http://localhost:4200/#/home';
const scopes = [
  'user-read-birthdate',
  'user-read-email',
  'user-read-private'
];

// If there is no token, redirect to Spotify authorization
if (!_token) {
  window.location = `${authEndpoint}?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scopes.join('%20')}&response_type=token`;
}
  }

在线

// Set token
let _token = hash.access_token;

我收到此错误:类型“ {}”上不存在属性“ access_token”

在这一部分:

if (!_token) {
  window.location = `${authEndpoint}?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scopes.join('%20')}&response_type=token`;
}

我遇到此错误:无法将类型“字符串”分配给类型“位置”。

非常感谢您。

0 个答案:

没有答案
相关问题