Angular 缺少必需的参数:在ionic2中访问google令牌时授予\类型
缺少必需的参数:在ionic2中访问google令牌时授予\类型 错误:-Angular 缺少必需的参数:在ionic2中访问google令牌时授予\类型,angular,ionic-framework,ionic2,Angular,Ionic Framework,Ionic2,缺少必需的参数:在ionic2中访问google令牌时授予\类型 错误:- { "error" : "invalid_request", "error_description" : "Required parameter is missing: grant_type" } let creds=JSON.stringify({ 'client_id':'251059024984-8113pdtb11gm8m4evdq59stlpvcab8cn.apps.googl
{
"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);
})
代码
{
"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时,它工作得非常完美
JSON.stringify()格式不正确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();
});
}
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);
}
services.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();
});
}
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);
}
登录(数据:任意):可观察{
让body=JSON.stringify(
'ClientId=5'+'&grant_type=password'
);
let headers=新的头({'Content Type':'application/x-www-form-urlencoded'});
let options=newrequestoptions({headers:headers});
console.log(数据)
使用post请求返回this.http.post(this.logindetail、body、options)/…文件
.map((res:Response)=>res.json())
.接住(这个.把手错误);
}
尝试删除json.stringify并只保留{}检查以下内容: