現在、Angular2のチュートリアルを進めています。残念ながら、私のチュートリアルでは、Spotify APIが今までに承認を必要としているとは言いません。私は既にSpotify Dev Cornerにアプリケーションを設定しました。私Angular2-サービスのための私のコードは、このAngular2サービス - Spotify API認可がCorsポリシーで失敗する
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class SpotifyService {
private searchUrl: string;
private token: string;
private client_id = 'xxxx';
private client_secret = 'yyyy';
private redirect_uri = 'http://localhost:4200';
private responseType = 'code';
constructor(private _http:Http){
}
authorize(){
return this._http
.get('https://accounts.spotify.com/authorize?client_id=' + this.client_id + '&client_secret=' + this.client_secret + '&redirect_uri=' + this.redirect_uri + '&response_type=' + this.responseType)
.map(res => res.json());
}
}
のように見え、私のコンポーネント内のコンストラクタはこの
constructor(private _spotifyService:SpotifyService) {
this._spotifyService.authorize().subscribe(res => {
console.log(res);
});
}
のように見える今、私の問題は、私のアプリを実行すると、私はクロスとエラーが出るということです私を少し混乱させる原産地の政策とヘッダーを正しく設定するのは本当にわかりません。
XMLHttpRequestはロードできません。 https://accounts.spotify.com/authorize?client_id=xxxx&client_secret=yyyy&redirect_uri=http://localhost:4200&response_type=code。 要求された リソースに「Access-Control-Allow-Origin」ヘッダーが存在しません。したがって、「http://localhost:4200」の原点は許可されません。
自分のdevifyコーナーの私のspotifyアプリケーションにredirect_uriを追加しました。多分あなたは助けてくれるかもしれません。 nginxのは、ApacheなどのHTTPサーバ上の事前のおかげと
挨拶クリスは
https://stackoverflow.com/questions/33029349/getting-spotify-api-access-token-with-node-js-express-js/ 33031590#33031590とhttps://stackoverflow.com/questions/24914853/authentication-request-to-spotify-web-api-rejected/24920670#24920670とhttps://stackoverflow.com/questions/33188989/allowing-cors- jquery-post-requests-to-spotify-express-js-server/33198424#33198424とhttps://github.com/spotify/web-api-auth-examplesはおそらく関連しています – sideshowbarker
進捗。あなたが取得リクエストによって黙認することはできないようですが、コンポーネント内のリンクとしてURLを使用する必要があります。私は私のアカウントと私のアプリケーションの間の接続を受け入れるよう求められている場所を特定するページに行く。だから私の唯一の質問は、私がリダイレクトした後です。私はどのように私のコンポーネントの応答データに戻ることができますか?これが解決された後、私は答えとしてここに再び完全なコードを掲示します – Chris