400错误请求 - https://accounts.google.com/o/oauth2/token

时间:2013-11-27 06:25:16

标签: google-oauth

任何人都可以告诉我为什么这是不好的要求

var searchurl = "https://accounts.google.com/o/oauth2/token";

    $.ajax({
        dataType: "json",
        url:searchurl,
        context: {code:auth_code, client_id:'clientid', client_secret:'secret', redirect_uri:'http%3A%2F%2Flocalhost:8085%2FGmailIntegration%2FgetAuthResponse.jsp', grant_type:'authorization_code'},
        type:"POST",
        contentType:"application/x-www-form-urlencoded",
        success:function(data) {
            alert(data);
        },
        error: function(jqXHR, exception) {
            console.log(jqXHR);

        }
    });

2 个答案:

答案 0 :(得分:2)

我有这个工作..我正在为那些坚持这个的人分享代码:

$.ajax({
        dataType: "json",
        url:searchurl,
        data: {code:code, client_id:'clientid', client_secret:'secret', redirect_uri:'http://localhost:8085/GmailIntegration/getAuthResponse.jsp', grant_type:'authorization_code'},
        type:"POST",
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        crossDomain:true,
        cache : true, 
        success:function(data) {
            alert(data);
        },
        error: function(jqXHR, exception, errorstr) {
            console.log(jqXHR);
            alert(errorstr);
        }
    });

但现在我有了新问题。网址得到200 OK响应,但我没有收到回复

enter image description here

答案 1 :(得分:0)

建议JS客户端使用OAuth2用户代理流程,请参阅https://developers.google.com/accounts/docs/OAuth2UserAgent

您是否有任何特定原因要在JS应用程序中使用Web服务器流程?