缺少必需参数:在ionic2中访问Google令牌时的grant_type
错误: -
{
"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);
})
当我检查邮递员的api工作完美时
答案 0 :(得分:4)
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()格式不正确
答案 1 :(得分:-1)
login.ts
onSubmit() {
console.log("hkjfghjksfgd")
this.showLoader();
this.authService.login(this.loginData).subscribe(
(data) => {
this.loading.dismiss();
this.result = data;
console.log(this.result)
localStorage.setItem('token', this.result.access_token);
}, (err) => {
this.loading.dismiss();
});
}
services.ts
login(data: any): Observable<any> {
let body = JSON.stringify(
'ClientId = 5'+'&grant_type = password'
);
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers });
console.log(data)
return this.http.post(this.logindetail, body, options) // ...using post request
.map((res: Response) => res.json())
.catch(this.handleError);
}