2016-10-03 57 views
1

所要求的参数谷歌令牌丢失:grant_type在访问谷歌令牌ionic2缺少必需的参数:grant_type在访问中ionic2

错误: -

{ 
    "error" : "invalid_request", 
    "error_description" : "Required parameter is missing: grant_type" 
} 

代码

let creds=JSON.stringify({ 
     'client_id':'251059024984-8113pdtb11gm8m4evdq59stlpvcab8cn.apps.googleusercontent.com', 
     'client_secret':'uVWZt_Vd5mMLXGQDo7lmAIUe', 
     'redirect_uri':'http://localhost/callback', 
     'grant_type':'authorization_code', 
     'code':data 
    }); 
    var headers = new Headers(); 
    headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    console.log(data) 


    this.http.post('https://accounts.google.com/o/oauth2/token',creds,{headers: headers}).map(res => res.json()).subscribe(data => { 
     console.log(data) 
    },(error)=>{ 
     console.log('error in', error); 
    }) 

当我检查邮差工作完美的工作

enter image description here

+0

尝试删除json.stringify,只留下{} – misha130

回答

2
let creds = 'client_id=251059024984-8113pdtb11gm8m4evdq59stlpvcab8cn.apps.googleusercontent.com' 
    +'&client_secret=uVWZt_Vd5mMLXGQDo7lmAIUe' 
    +'&redirect_uri=http://localhost/callback' 
    +'&grant_type=authorization_code' 
    +'&code=' + data 

JSON.stringify()是不正确的格式

+0

检查了这一点:http://stackoverflow.com/questions/35212341/angular2-HTTP-POST请求参数 –

相关问题