getJson解析器没有'不起作用

getJson parser doesn't work

本文关键字:不起作用 getJson      更新时间:2023-09-26

嗨,我正在尝试解析url的json响应,但我做不到。

$(document).ready(function() {
    $.getJSON('https://www.googleapis.com/oauth2/v1/userinfo?&access_token=xxxxxxxxxxxxx&token_type=Bearer&expires_in=3600', function(data) {
        alert (c.email);
    });
});

在这个页面中有我的代码http://pastie.org/3379735

我希望你能帮助我。

什么是c.email,认为你想要data.email

$(document).ready(function() {
  $.getJSON('https://www.googleapis.com/oauth2/v1/userinfo?&access_token=xxxxxxxxxxxxx&token_type=Bearer&expires_in=3600&callback=?', function(data) {
    alert (data.email);
  });
});

更新

正如OP在阅读文档后所说的那样,您需要为jsonp提供回调作为路径的一部分,而不是形式的params

https://oauth2-login-demo.appspot.com/oauthcallback?code={authorizationCode}

文档可以在这里找到

由于同源策略限制,您无法发送跨域AJAX请求。没有JSONP对此的支持,所以你不能直接从你的代码中访问他的url。

您可以查看以下基于gwt-oauth2.js脚本的演示,该脚本使用此代码向Google进行身份验证。