php - 使用 LightOpenID 获取 Google 通讯录?

标签 php google-api google-contacts-api lightopenid

我目前正在使用 LightOpenID 允许用户登录我的站点,我可以在其中自动提取他们的用户名和电子邮件地址:

$openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
$openid->identity = 'https://www.google.com/accounts/o8/id';

我在这里使用参数 namePerson/firstnamePerson/lastcontact/email

我知道为了获得用户联系人列表,我必须使用提要:

https://www.google.com/m8/feeds

但是,我似乎无法弄清楚为此需要使用哪些参数?

如果我完全删除参数行,我只会得到一个空数组。

谁能帮我弄清楚获取联系人需要哪些参数?

这是我目前的代码:

<?php
    require '/var/www/libraries/openid.php';

    try {

        $openid = new LightOpenID;

        if(!$openid->mode) {

            //$openid->required = array('gd/fullName');
            $openid->identity = 'https://www.google.com/m8/feeds/contacts/oshirowanen.y%40gmail.com/full';
            header('Location: ' . $openid->authUrl());
            exit;

        } elseif($openid->mode == 'cancel') {

            echo "cancelled";
            exit;

        } else {

            if ( $openid->validate() ) {

                $returned = $openid->getAttributes();
                print_r($returned);

                exit;

            } else {

                echo "something is wrong";
                exit;

            }

        }

    } catch(ErrorException $e) {

        echo $e->getMessage();

    }
?>

最佳答案

你不能用 LightOpenID 做到这一点,因为它只实现了 OpenID 协议(protocol)。

您将需要 OAuth (2.0) 协议(protocol)来执行此操作。每the docs :

About authorization protocols

We recommend using OAuth 2.0 to authorize requests.

If your application has certain unusual authorization requirements, such as logging in at the same time as requesting data access (hybrid) or domain-wide delegation of authority (2LO), then you cannot currently use OAuth 2.0 tokens. In such cases, you must instead use OAuth 1.0 tokens and an API key. You can find your application's API key in the Google API Console, in the Simple API Access section of the API Access pane.

关于php - 使用 LightOpenID 获取 Google 通讯录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11176915/

相关文章:

php - MySQL 调用所有值的更简单方法,而不是在 INNER JOIN 中单独调用它们

php - PHP 中简单的 3 个字母日

php - 调用 PHP Web 服务时,来自 iOS 的 $_POST 数据丢失

google-apps-script - 您没有调用 getContacts 的权限

javascript - 复选框启用只读输入不工作

javascript - Google api - 防止标记在缩放时改变大小

youtube - 从YouTube API中自动生成的 channel 中获取视频

javascript - Google 不是使用 Google Visualization API 定义的;可能是 jQuery 的错

android - google 的 People API 与 contacts API

php - Google Contacts API 获取电话号码 (PHP)