4

关于从一些授权我的应用程序并使用它的 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);
     }
     ?>
4

2 回答 2

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

它应该是

$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)");
于 2012-09-15T18:43:50.180 回答
1

Problem was with the object type in the database. Some facebook users have incredebly large id: 0098788563000236 for example, so using BIGINT instead of INT solved it.

于 2012-11-29T14:12:47.037 回答