使用LightOpenID获取Google通讯录?

osh*_*nen 7 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';
Run Code Online (Sandbox Code Playgroud)

在这里我使用的参数namePerson/first,namePerson/lastcontact/email.

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

https://www.google.com/m8/feeds
Run Code Online (Sandbox Code Playgroud)

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

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

任何人都可以帮我弄清楚我需要哪些参数来获取联系人?

这是我目前的代码:

<?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();

    }
?>
Run Code Online (Sandbox Code Playgroud)

Ali*_*xel 5

您无法使用LightOpenID执行此操作,因为它仅实现OpenID协议.

您需要OAuth(2.0)协议才能执行此操作.根据文档:

关于授权协议

我们建议您使用OAuth 2.0来授权请求​​.

如果您的应用程序具有某些不寻常的授权要求,例如在请求数据访问(混合)或域范围授权(2LO)的同时登录,则您当前无法使用OAuth 2.0令牌.在这种情况下,您必须使用OAuth 1.0令牌和API密钥.您可以在API API控制台的"API访问"窗格的"简单API访问"部分中找到应用程序的API密钥.