angular – 缺少必需参数:在ionic2中访问google令牌时的grant_type

前端之家收集整理的这篇文章主要介绍了angular – 缺少必需参数:在ionic2中访问google令牌时的grant_type前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
缺少必需参数:在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工作完美

enter image description here

解决方法

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()不是正确的格式

猜你在找的Angularjs相关文章