谷歌登录集成

3
我对社交网络登录API非常陌生。现在我正在进行谷歌登录集成方面的工作。
我已经使用OpenID示例类进行了测试,结果如下所示:https://www.google.com/accounts/o8/id?id=ID
我该如何从中获取值(用户信息、好友列表等)?
我需要为此创建任何谷歌应用程序吗?
请问有人能帮助我集成吗?
感谢您的关注。
1个回答

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。或许这个链接会对您有所帮助=> http://docs.opensocial.org/display/OSD/Integrating+your+PHP+site+with+Google+Friend+Connect+and+Open+Social


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接