开发者

Google login integration

I am very new to the social network login API's. Now i am working in the google 开发者_如何学编程login integration.

I have tested with the openid sample classes and got like following:

https://www.google.com/accounts/o8/id?id=ID

How can i fetch the values (user information,friends list etc) from this ?

I need to create any google Application for this ?

Could you please any one help me to integrate this.

Thank you for looking in to this.


You can rather easily accesss user information with LightOpenID. You can access AX / SREG extensions very easily

> AX and SREG extensions are supported.  * To use them, specify
> $openid->required and/or $openid->optional before calling
> $openid->authUrl().  * These are arrays, with values being AX schema
> paths (the 'path' part of the URL).  * For example:  *  
> $openid->required = array('namePerson/friendly', 'contact/email');  * 
> $openid->optional = array('namePerson/first');  * If the server
> supports only SREG or OpenID 1.1, these are automaticaly  * mapped to
> SREG names, so that user doesn't have to know anything about the
> server.
> To get the values, use $openid->getAttributes().

<?php

# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try {
    $openid = new LightOpenID;
    $openid->required = array('namePerson/friendly', 'contact/email');
    $openid->optional = array('namePerson/first');

    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'https://www.google.com/accounts/o8/id';
            header('Location: ' . $openid->authUrl());
        }
?>
<form action="?login" method="post">
    <button>Login with Google</button>
</form>
<?php
    } elseif($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
        echo "<p>";
        print_r($openid->getAttributes());
        echo "</p>";
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}


` print_r($openid->getAttributes());` shows email name which was required because `$openid->required = array('namePerson/friendly', 'contact/email');` I wonder why friendly is not shown, but I don't even think I set one for gmail.

To get friends list information you should probably study Google Friend Connect. Maybe this link might help you => http://docs.opensocial.org/display/OSD/Integrating+your+PHP+site+with+Google+Friend+Connect+and+Open+Social

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜