Question

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

    }
?>
Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top