Unable to get access and refresh token after authenticating with Google API

强颜欢笑 提交于 2019-12-04 14:10:49

After 3 days I did it. Thanks for the console.log tip, @Brunt!

$.ajax({
            url: 'https://www.googleapis.com/oauth2/v4/token',
            type: "post",
            datatype:"json",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            async : true,
            data: {code:code, client_id:clientId, client_secret:clientSecret, redirect_uri:'https://mywebsite.com/quickstart.html', grant_type:'authorization_code'},
            success: function(response){
                console.log("Response: " + response);
                console.log("AT: " + response['access_token']);
                console.log("RT: " + response['refresh_token']);

                access_token = response['access_token'];
                refresh_token = response['refresh_token'];
            }
        })
        .fail(function(err) {
            alert("error" + err); //[Object object]
            console.log("error" + err);
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!