如何使用Janrain basic获取用户的电子邮件地址

问题描述:

I'm trying to get users email addresses when they log in so I can they can be entered into my database and given a unique ID. I've managed to retrieve user display names and store them in the database using this code however its not working with the email address.

session_start();
            if(property_exists($profile->profile,'displayName')){
                $_SESSION['username'] = $profile->profile->displayName;
                $_SESSION['email'] = $profile->profile->email;
                $_SESSION['logged']="logged";

                $username = $_SESSION['username'];
                $email = $_SESSION['email'];

                require_once("db_connect.php");
                $query="SELECT email FROM users WHERE email = '$email'";
                mysqli_select_db($db_server, $db_database);
                $result=mysqli_query($db_server, $query);
                if($result != $email){
                    $query = "INSERT INTO users (username, email) VALUES ('$username', '$email')";
                    mysqli_query($db_server, $query) or
                                die("Insert failed. ". mysqli_error($db_server));
                }else{
                    echo "Login error.";    
                }

                mysqli_free_result($result);
                require_once("db_close.php");
                header('location:home.php');
            }else{
                $_SESSION['username'] = '(Anonymous)';
                $_SESSION['logged']="logged";
                header('location:home.php');
          } 

Thanks for your help.

我正在尝试在用户登录时获取用户的电子邮件地址,这样我就可以将它们输入到我的数据库中 给出一个唯一的ID。 我已设法检索用户显示名称并使用此代码将它们存储在数据库中,但它不能使用电子邮件地址。 p>

  session_start(); 
 if(property_exists($ profile-> profile,'displayName')){
 $ _SESSION ['username'] = $ profile-  >个人资料 - > displayName; 
 $ _SESSION ['email'] = $个人资料 - >个人资料 - >电子邮件; 
 $ _SESSION ['logged'] =“已登录”; 
 
 $ username =  $ _SESSION ['username']; 
 $ email = $ _SESSION ['email']; 
 
 require_once(“db_connect.php”); 
 $ query =“SELECT email FROM users WHERE email ='$ email  '
';; 
 mysqli_select_db($ db_server,$ db_database); 
 $ result = mysqli_query($ db_server,$ query); 
 if($ result!= $ email){
 $ query =“INSERT INTO users( 用户名,电子邮件)VALUES('$ username','$ email')“; 
 mysqli_query($ db_server,$ query)或
 die(”插入失败。“。mysqli_error($ db_server)); 
} else  {
 echo“登录错误。”;  
} 
 
 mysqli_free_result($ result); 
 require_once(“db_close.php”); 
 header('location:home.php'); 
} else {
 $ _SESSION ['username'  ] ='(匿名)'; 
 $ _SESSION ['logged'] =“已记录”; 
标题('location:home.php'); 
} 
  code>  pre> 
  
 

感谢您的帮助。 p> div>

It sounds like it has to do with what information the providers share by default. I believe these steps should fix it:

  1. Log in to https://dashboard.janrain.com/
  2. Select your Engage application
  3. In the "Providers" box, hover over the one that you are trying to authenticate with
  4. Click the small wrench icon that appears after you've hovered over the provider
  5. Make sure that the "Ask" box is checked next to "email"

Let me know if that works out for you!