Getting Google Contacts using LightOpenID?
Asked Answered
G

3

7

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

    }
?>
Geminian answered 24/6, 2012 at 11:4 Comment(1)
Added all the code I currently have above.Geminian
C
5

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.

Comminute answered 1/7, 2012 at 23:10 Comment(1)
Thanks for this Alix, I started digging into it, but didn't want to spend too long.., I need to ramp up on OAuth.Reprieve
R
0

Per the docs:

Retrieving all contacts

To retrieve all of a user's contacts, send an authorized GET request to the following URL:

https://www.google.com/m8/feeds/contacts/{userEmail}/full

With the appropriate value in place of userEmail.

Note: The special userEmail value default can be used to refer to the authenticated user.

Reprieve answered 28/6, 2012 at 19:38 Comment(3)
I've tried that already using LightOpenID, and I just get an empty array back. I have included the full code I currently have in the original question above.Geminian
fair enough, I'll give it a closer lookReprieve
This answer is correct, but the question is wrong. Which, I think, makes both of them wrong. :PComminute
F
0

It should be possible as per the docs: https://developers.google.com/accounts/docs/OpenID

OpenID+OAuth Hybrid protocol lets web developers combine an OpenID request with an OAuth authentication request. This extension is useful for web developers who use both OpenID and OAuth, particularly in that it simplifies the process for users by requesting their approval once instead of twice.

Fleecy answered 8/8, 2012 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.