从刷新令牌oauth google获取令牌

时间:2018-01-11 09:44:24

标签: javascript reactjs react-native ecmascript-6 google-authentication

您好我正在使用刷新令牌生成令牌,它正在使用ajax调用正常工作,但现在我必须使用相同的代码进行react-native但我收到invalid_grant_type错误,我的代码如下:

 fetch('https://www.googleapis.com/oauth2/v3/token', {
            method: 'POST',
            timeout: 30000,
            headers: {
                'Accept': 'application/json;application/x-www-form-urlencoded',
                'Content-Type': 'application/x-www-form-urlencoded;application/json'
            },
            body: JSON.stringify({
                client_id: this.client_id,
                client_secret: this.secret,
                refresh_token: globalRefreshAccessToken,
                grant_type: 'refresh_token'
            })
        }).then((response) => response.json())
            .then((responseData) => {
                console.log(JSON.stringify({
                    client_id: this.client_id,
                    client_secret: this.secret,
                    refresh_token: globalRefreshAccessToken,
                    grant_type: 'refresh_token'
                }));
                debugger;
                // callback(responseData);
            })
            .catch((error) => {
                debugger;
                console.log(error)
                //  errorcallback(error);
            });

0 个答案:

没有答案