提问者:小点点

如何从googleapi令牌获取数据?


我想在我的网站中使用Google登录凭据。所以我使用Google API。我在URL中获得了一个google API令牌。所以我想获取登录用户数据?我使用的是C#。成功登录并重定向回我的网站后,我得到了这个URL:-

http://localhost:20885/WebServices/Welcome.aspx#state=/profile

请帮助我。

提前感谢。


共2个答案

匿名用户

看看这个。网络图书馆

http://www.dotnetopenauth.net/

这将为您完成所有繁重的OpenID / OAuth工作。你只需要把它指向谷歌的OpenID URL。

请求特定的用户数据(例如电子邮件)很容易,并在此处解释:

https://developers.google.com/accounts/docs/OpenID

匿名用户

在您的。aspx页面:

// First, parse the query string
var params = {}, queryString = location.hash.substring(1),
regex = /([^&=]+)=([^&]*)/g, m;
while (m = regex.exec(queryString)) {
  params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}

// And send the token over to the server
var req = new XMLHttpRequest();
// consider using POST so query isn't logged
req.open('GET', 'http://' + window.location.host + '/public/Google.aspx?' + queryString, true);

req.onreadystatechange = function (e) {
  if (req.readyState == 4) {
    if (req.status == 200) {
      window.location = params['state']
    }
    else if (req.status == 400) {
      alert('There was an error processing the token.')
    }
    else {
      alert('something else other than 200 was returned')
    }
  }
};
req.send(null);

使用它来调用相同或另一个. aspx页面。