首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google登录集成

Google登录集成
EN

Stack Overflow用户
提问于 2011-06-02 11:21:05
回答 1查看 2.2K关注 0票数 3

我对社交网络的登录API非常陌生,现在我正在google登录集成中工作。

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

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

如何从中获取值(用户信息、好友列表等)?

我需要为这个创建谷歌应用程序吗?

你能帮我把这个整合起来吗。

谢谢你能参与进来。

EN

回答 1

Stack Overflow用户

发布于 2011-07-15 01:46:12

您可以很容易地使用LightOpenID访问用户信息。您可以非常容易地访问AX / SREG扩展。

代码语言:javascript
复制
> 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().
代码语言:javascript
复制
<?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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6213851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档