Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Google Contacts using LightOpenID?

I am currently using LightOpenID to allow users to log into my site, where I can automatically extract their username and email address:

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

Here I am using the parameters namePerson/first, namePerson/last, and contact/email.

I understand that inorder to get a list of user contacts, I have to use the feed:

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

However, I can't seem to figure out which parameters I need to use for this?

If I remove the paramter line altogether, I just get an empty array back.

Can anyone please help me figure out which parameters I need to get the contacts?

Here is the current code I have:

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

    }
?>
like image 610
oshirowanen Avatar asked Jun 24 '12 11:06

oshirowanen


1 Answers

You can't do that with LightOpenID because it only implements the OpenID protocol.

You will need the OAuth (2.0) protocol to do that. Per 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.

like image 187
Alix Axel Avatar answered Sep 22 '22 12:09

Alix Axel