问题描述
我很困惑.
我能够使用 LightOpenID 使openid登录工作正常.
I was able to make openid login kinda work using LightOpenID.
我所做的只是一个openid_identity
,例如"https://www.google.com/accounts/o8/id?id=xxx
".非常令人失望:我也希望获得电子邮件地址.
All I get doing that is just an openid_identity
such as "https://www.google.com/accounts/o8/id?id=xxx
". Pretty disappointing: I was expecting to get the email address too.
即我需要登录(这就是openid的功能) 和,以了解用户用于登录的Google帐户的电子邮件地址.
i.e. I need to login (that's what openid does) and to know the email address of the google account the user used to login.
有功能$openid->getAttributes()
,但是我从中得到的只是一个空数组:我想Google除了提供openid_identity
之外不会给我任何东西.
There is the function $openid->getAttributes()
but all I get from that is just an empty array: I guess google isn't going to give me anything else than that openid_identity
.
所以我猜我应该使用OAuth
,对吗?我对此一无所知.我只发现了可怕而混乱的文档,要么假装解释了一切(而我却是指一切),要么却无法解释< .
So I guess I'm supposed to use OAuth
, right?I'm clueless about that.I've only found horrible and confused documentation, that either pretends to explain everything (and I do mean everything), or it fails explain anything at all.
是的,当然,正如我在Google上搜索时一样,我尝试查看有关该内容的以前的帖子.请再次阅读以上段落.
Yes, of course I've tried to look at the previous posts about that, just as I did search on google. Read again the above paragraph, please.
推荐答案
我刚刚发现了 LightOpenID ,我认为这很棒.通过example-gmail.php
的以下修改,我设法获得了电子邮件地址,名字和首选语言:
I've just discovered LightOpenID and I think it's wonderful. I've managed to get the email address, the first and last name and the prefered language using the following modification of example-gmail.php
:
<?php
require_once('openid.php');
if (empty($_GET['openid_mode']))
{
if (isset($_GET['login']))
{
$openid = new LightOpenID();
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->required = array('namePerson/first', 'namePerson/last', 'contact/email', 'pref/language');
header('Location: ' . $openid->authUrl());
//header('Location: ' . str_replace('&', '&', $openid->authUrl()));
}
else
{
echo '<form action="?login" method="post">' . "\n";
echo '<button>Login with Google</button>' . "\n";
echo '</form>' . "\n";
}
}
else if ($_GET['openid_mode'] == 'cancel')
{
echo 'User has canceled authentication!';
}
else
{
$openid = new LightOpenID();
echo 'User ' . ($openid->validate() ? $_GET['openid_identity'] . ' has ' : 'has not ') . 'logged in.';
echo '<pre>';
print_r($openid->getAttributes());
echo '</pre>';
}
?>
我更改了代码以使其更具可读性,即输出:
I changed the code to make it a little more readable, the output:
User https://www.google.com/accounts/o8/id?id=*** has logged in.
Array
(
[namePerson/first] => Alix
[contact/email] => ***@gmail.com
[pref/language] => en
[namePerson/last] => Axel
)
我仍然无法从Google获得邮政编码和其他邮政编码,但是我在 myOpenID.com 上取得了成功.
I still can't get the postal code and others from Google but I've had success with myOpenID.com.
这篇关于获取带有... openid的Gmail地址? oauth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!