2013-04-12 18 views
0

我有這樣的修改谷歌,例如連接代碼lightOpenId:來自openId的空用戶信息,爲什麼?

<?php 
require_once('../db.php'); 
session_start(); 
# Logging in with Google accounts requires setting special identity, so this example shows how to do it. 
require 'openid.php'; 
try { 
    # Change 'localhost' to your domain name. 
    $openid = new LightOpenID('127.0.0.1'); 
    if(!$openid->mode) { 
     if(isset($_GET['login'])) { 
      $openid->identity = 'https://www.google.com/accounts/o8/id'; 
      $openid->required = array('contact/email'); 
      $openid->optional = array('namePerson', 'namePerson/friendly'); 
      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 { 
     if ($openid->validate()) { 
      $_SESSION['auth'] = $openid->identity; 

      $userinfo = $openid->getAttributes(); 
      print_r($openid->required); 
      echo $_SESSION['auth']; 

      $stmt = $dbh->prepare("INSERT INTO users(id,name,email) VALUES(:id,:name,:email)"); 
      $stmt->execute(array(":id" => $openid->identity, 
           ":name" => "name", 
           ":email" => "name")); 
     } 
    } 
} catch(ErrorException $e) { 
    echo $e->getMessage(); 
} 

我的問題是$ openid->不返回任何要求。數組本身甚至不包含空的「聯繫人/電子郵件」字段。我在這裏做錯了什麼?

回答

0

$openid->required不會在請求之間保留,但您不必使用它。

至於$userinfo爲空,它只包含由提供者返回的字段(例如,沒有字段),無論您要求什麼。

提供程序可能會返回您請求的字段,但它不必甚至不必支持返回任何其他數據(因爲這是一個協議擴展)。

相關問題