2017-05-14 12 views
-1

私のウェブサイトでyahoo oauthを使用しました。たとえば、$user -> query -> results -> profile -> givenNameのように、githubで見つかったコードでは、ログインしたユーザーのファーストネーム、つまり$user -> query -> results -> profile -> familyNameなどが返されます。 私は多くを検索しましたが、ユーザーのメールアドレスを取得する方法はまだ分かりません。PHPでoauthを使用してユーザの電子メールにログインした方法

これは私のコードです:

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

ようこそstackoverflow。特定の問題のコードを提供してください。それはあなたがどれだけ試してみたのかを証明し、他のメンバーがあなたの問題をより良く理解するのを助けます。その時、あなたは問題の文脈を与えます。これらのリンクを確認してください:https://stackoverflow.com/help/mcveおよびhttps://stackoverflow.com/help/how-to-ask –

答えて

関連する問題