我在我的网站上使用了yahoo oauth。在我在github上找到的代码中,例如$user -> query -> results -> profile -> givenName
返回登录用户的名字,$user -> query -> results -> profile -> familyName
,依此类推。
我搜索了很多但仍然不知道如何获取用户的电子邮件地址。
这是我的代码:
require('include/http.php');
require('include/oauth_client.php');
$client = new oauth_client_class;
$client->debug = false;
$client->debug_http = true;
$client->server = 'Yahoo';
$client->redirect_uri = 'http://www.example.com';
$client->client_id = '';
$application_line = __LINE__;
$client->client_secret = '';
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
'https://query.yahooapis.com/v1/yql',
'GET', array(
'q'=>'select * from social.profile where guid=me',
'format'=>'json'
), array('FailOnAccessError'=>true), $user);
}
}
$success = $client->Finalize($success);
}
if($client->exit)
exit;
if(strlen($client->authorization_error))
{
$client->error = $client->authorization_error;
$success = false;
}
if($success)
{
$yahname =$user->query->results->profile->givenName.$user->query->results->profile->familyName;
echo '<pre>', HtmlSpecialChars(print_r($user, 1)), '</pre>';
}
else
{
echo HtmlSpecialChars($client->error);
}
如果我做错了,请告诉我。
答案 0 :(得分:0)
我不相信该个人资料包含用户的电子邮件地址(Yahoo profile docs中未列出)。如果您已sdpp-w
范围请求id token,则exchanging an authorization code for an access token包含密钥email
下用户的电子邮件地址。