How have logged in user's email using oauth in PHP

113 views Asked by At

I used yahoo oauth in my website. In code below that I found on github, for example $user -> query -> results -> profile -> givenName returns the first name of logged in user, $user -> query -> results -> profile -> familyName and so on. I searched a lot but still I don't know how to get user's email address.

This is my code :

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

Please let me know if I am doing anything wrong.

1

There are 1 answers

0
chesterm8 On

I do not believe that the profile contains the users email address (it is not listed in the Yahoo profile docs). If you have requested the sdpp-w scope the the id token you get when exchanging an authorization code for an access token contains the email address of the user under the key email.