2017-11-22 4 views
0

Google Apiサービスでベアラトークンの認証コードを交換する必要があります。 Oauth2の流れを表すOauthPlaygroundという素晴らしいアプリケーションがあります。トークンは、それがこのような要求を使用してExchange用:角交換がベアラトークンのトークンにアクセスするOauth2

POST /oauth2/v4/token HTTP/1.1 
Host: www.googleapis.com 
Content-length: 233 
content-type: application/x-www-form-urlencoded 
user-agent: google-oauth-playground 

code=4%2F6RMgcR3WKuY8_bIaZa0o8P6xfxMKZh1f6AZmh9Q-h6Y&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=407408718192.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code 

私はGoogle developer consoleで私のアプリケーションを登録し、自分のclient_idとclient_secretを持っています。リクエストで送信された例の体がある

tryGetBearers(){ 
    let connString='www.googleapis.com/oauth2/v4/token'; 
    let connBody='code='+this.accessToken; 
    connBody+='&redirect_uri='+this.redirect_uri 
    connBody+='&client_id='+this.client_id 
    connBody+='&client_secret='+this.client_secret 
    connBody+='&scope=&grant_type=authorization_code' 

let headers = new Headers(); 
headers.append('content-type', 'application/x-www-form-urlencoded'); 
    this.http.post(connString,connBody,{headers:headers}).subscribe(
     res=>{console.log(res);}, 
     (error)=>{console.log(error); 
     } 
    ); 
    } 

:ない作品をする私のコードは以下の通りです

code=4/Q5p52c8zMfwzAKErog-7QUJzv7aYGyAlCDz_5KE0Mgw&redirect_uri=http://localhost:4200&client_id=665991054229-jmd9i1ovcohglkrlbu1ff1nih9j1cqia.apps.googleusercontent.com&client_secret=hnrh1eGPKFmdEWkdWna7zs6K&scope=&grant_type=authorization_code 

機能の応答は、ちょうど404見つかりません。私は何が間違っているのか分かりません。

答えて

0

私は、URLが悪いことがわかりました。代わりにこれを使用して

let connString='www.googleapis.com/oauth2/v4/token'; 

のokです:

let connString='https://accounts.google.com/o/oauth2/token' 
関連する問題