php – 一些未插入mysql数据库的Facebook用户的数据

关于从授权我的应用程序并使用它的一些Facebook用户那里获取数据(通常是顺便说一句),我有一个奇怪但非常严重的问题.

到目前为止,大约有3000个用户使用过该应用程序,但只有600个用户在用户表中显示.怎么可能呢?我无法找到新旧用户之间的联系 – 对于一些用户而言,它可以完美地工作,对于其他用户而言根本不起作用.

这是完整的,但出于安全考虑,审查代码:

<?php
 require 'facebook.php';
 include 'config.php';
 session_start();

 $app_id = 'id';
 $app_secret = 'secret';
 $app_namespace = 'namespace';
 $app_url = 'https://apps.facebook.com/' . $app_namespace . '/';
 $scope = 'email,publish_actions';

//初始化Facebook SDK

    $facebook = new Facebook(array(
    'appId'  => $app_id,
    'secret' => $app_secret,
    'cookie' => true
    ));

//获取当前用户

 $user = $facebook->getUser();

//如果用户尚未安装应用程序,请将其重定向到Auth Dialog

 if (!$user) {
    $loginUrl = $facebook->getLoginUrl(array(
    'scope' => $scope,
    'redirect_uri' => $app_url,
    ));

print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
 }

 else if ($user) {
    try {

//继续了解我们已经有一个已经过身份验证的登录用户.

    $fbuid = $facebook->getUser();
    $user_profile = $facebook->api('/me');



} catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
}
 }
else{
header('Location: index.php');

 }
 $queryUserExists = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook'AND oauth_uid = " . $user_profile['id']);
 $num=mysql_numrows($queryUserExists);

//如果没有,请将其添加到数据库中

 if ($num == 0) {
$query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, email, pic_square ,login_date , dailytokens) 
        VALUES ({$user_profile['id']}, 'facebook', '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['email']}', '".$photolink."',CURDATE(),1)");
$query = mysql_query("SELECT * FROM users WHERE oauth_uid = " . mysql_insert_id());
$result = mysql_fetch_array($query); 
 }
     else
     {
    $DateLastLogin=mysql_result($queryUserExists,0,"login_date");
    $myDate = date('Y-m-d');

    $CompLastDate = strtotime($DateLastLogin);
    $CompMyDate = strtotime($myDate);

if($CompLastDate < $CompMyDate){
    $updateDailyToken = "Update users set login_date=CURDATE(), dailytokens = dailytokens + 1 where oauth_uid =" . $user_profile['id'];
    $updateToken= mysql_query($updateDailyToken) or die(mysql_error());
}
 }
 $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND oauth_uid = " . $user_profile['id']);

 $_SESSION['userid']=$user_profile['id'];

//根据当前用户状态,将需要登录或注销URL.

     if ($user) {
    $paramsout = array('next'=>'http://facebook.com');
    $logoutUrl = $facebook->getLogoutUrl($paramsout);
     }
     ?>

最佳答案 这是你的问题

$query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, email, pic_square ,login_date , dailytokens) 
        VALUES ({$user_profile['id']}, 'facebook', '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['email']}', '".$photolink."',CURDATE(),1)");

它应该是

$query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, email, pic_square ,login_date , dailytokens) 
        VALUES ('{$user_profile['id']}', 'facebook', '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['email']}', '{$photolink}',CURDATE(),1)");
点赞