Google登录集成

时间:2011-06-02 11:21:05

标签: php login

我是社交网络登录API的新手。现在我正在进行谷歌登录集成。

我已经使用openid示例类进行了测试,结果如下:

https://www.google.com/accounts/o8/id?id=ID

如何从此处获取值(用户信息,朋友列表等)?

我需要为此创建任何Google应用程序吗?

你能不能请任何人帮我整合这个。

感谢您关注此事。

1 个答案:

答案 0 :(得分:1)

您可以使用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.

要获取朋友列表信息,您应该研究Google Friend Connect。也许这个链接可能会帮助你=&gt; http://docs.opensocial.org/display/OSD/Integrating+your+PHP+site+with+Google+Friend+Connect+and+Open+Social

相关问题