我对社交网络的登录API非常陌生,现在我正在google登录集成中工作。
我使用openid示例类进行了测试,得到如下结果:
https://www.google.com/accounts/o8/id?id=ID
如何从中获取值(用户信息、好友列表等)?
我需要为这个创建谷歌应用程序吗?
你能帮我把这个整合起来吗。
谢谢你能参与进来。
发布于 2011-07-15 01:46:12
您可以很容易地使用LightOpenID访问用户信息。您可以非常容易地访问AX / SREG扩展。
> AX and SREG extensions are supported. * To use them, specify
> $openid->required and/or $openid->optional before calling
> $openid->authUrl(). * These are arrays, with values being AX schema
> paths (the 'path' part of the URL). * For example: *
> $openid->required = array('namePerson/friendly', 'contact/email'); *
> $openid->optional = array('namePerson/first'); * If the server
> supports only SREG or OpenID 1.1, these are automaticaly * mapped to
> SREG names, so that user doesn't have to know anything about the
> server.
> To get the values, use $openid->getAttributes().<?php
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try {
$openid = new LightOpenID;
$openid->required = array('namePerson/friendly', 'contact/email');
$openid->optional = array('namePerson/first');
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/id';
header('Location: ' . $openid->authUrl());
}
?>
<form action="?login" method="post">
<button>Login with Google</button>
</form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
echo "<p>";
print_r($openid->getAttributes());
echo "</p>";
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
` print_r($openid->getAttributes());` shows email name which was required because `$openid->required = array('namePerson/friendly', 'contact/email');` I wonder why friendly is not shown, but I don't even think I set one for gmail.要获得好友列表信息,你应该学习谷歌好友连接。也许这个链接可以帮助您=> http://docs.opensocial.org/display/OSD/Integrating+your+PHP+site+with+Google+Friend+Connect+and+Open+Social
https://stackoverflow.com/questions/6213851
复制相似问题