同步两个表user_id,并感谢用户与Twitterouth的确认


sync two table user_id and thanks confirmation to user with twitter oauth

所以这是我昨天提出的问题中的一种后续问题,这个问题已经解决了。

但现在我有另一个问题。我一直在尝试从链接的同一数据库中的 2 个不同表中获取user_id,因此当用户验证他们的 Twitter 时,它会显示一个内页,上面写着*您已经链接了您的 twitter!"用户名",因此所有页面的 2 个表格布局和代码如下:

用户表:此表适用于 Twitter OAuth

ID, user_id, oauth_provider, oauth_uid, 用户名, fname, lname, 区域设置, oauth_token, oauth_secret, 图片, 创建, 修改

积分表:此表

用于积分和YouTube内容,(此表user_id已经从我的phpBB数据库中获取phpbb_users表中的数据。

user_id, 用户名, yt_channelTitle, 积分, user_email, access_token, refresh_token, channel_id, 上传, 每日投票

推特 OAuth 函数.php文件:

function checkUsers($user_id,$oauth_provider,$oauth_uid,$username,$fname,$lname,$locale,$oauth_token,$oauth_secret,$profile_image_url){
    $prevQuery = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
    if(mysqli_num_rows($prevQuery) > 0){
        $update = mysqli_query($this->connect,"UPDATE $this->tableName SET  oauth_token = '".$oauth_token."', oauth_secret = '".$oauth_secret."', modified = '".date("Y-m-d H:i:s")."', user_id = '".$user_id."' WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."' AND user_id = '".$user_id."' ") or die(mysqli_error($this->connect));
    }else{
        $insert = mysqli_query($this->connect,"INSERT INTO $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."', username = '".$username."', fname = '".$fname."', lname = '".$lname."', locale = '".$locale."', oauth_token = '".$oauth_token."', oauth_secret = '".$oauth_secret."', picture = '".$profile_image_url."', created = '".date("Y-m-d H:i:s")."', modified = '".date("Y-m-d H:i:s")."', user_id = '".$user_id."' ") or die(mysqli_error($this->connect));
    }
    $query = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
    $result = mysqli_fetch_array($query);
    return $result;
}

twitteroauth process.php file:

    include_once("../inc/header_session.php");
#$user_id = getUserInfo($id,$user->data['user_id']);
$user_id = intval($user->data['user_id']);
if($connection->http_code == '200' && $user_id != 1)
{
    //Redirect user to twitter
    $_SESSION['status'] = 'verified';
    $_SESSION['request_vars'] = $access_token;
    //Insert user into the database
    $user_info = $connection->get('account/verify_credentials'); 
    $user_id = $user->data['user_id'];
    $name = explode(" ",$user_info->name);
    $fname = isset($name[0])?$name[0]:'';
    $lname = isset($name[1])?$name[1]:'';
    $db_user = new Users();
    $db_user->checkUsers($user_info->user_id,'twitter',$user_info->id,$user_info->screen_name,$fname,$lname,$user_info->lang,$access_token['oauth_token'],$access_token['oauth_token_secret'],$user_info->profile_image_url,$user_info);
    //Unset no longer needed request tokens
    unset($_SESSION['token']);
    unset($_SESSION['token_secret']);
    header('Location: /twitter.php');
}else{
    die("error, try again later!");
}

现在推特.php页面 https://www.tubenations.com/twitter.php

if ($user_login == 1){
echo '<h1 class="icon fa-twitter"> Twitter Page!</h1>';
    $user_id = intval($user->data['user_id']);
    include "twitter/includes/functions.php";
    #$user_info = checkUsers($user_id,$oauth_provider,$oauth_uid,$username,$fname,$lname,$locale,$oauth_token,$oauth_secret,$profile_image_url);
    echo $oauth_uid;
    if (empty($user_info['oauth_uid'] == 1))
        {
            echo '
            <div class="row">
                    <div class="8u">                    
                        <br />
                        <div class="twitterInfo2">IMPORTANT ANNOUNCEMENT: We are currently trying to setup a twitter authentication system, so that users have to authenticate their twitter accounts 
                        in order for them to be displayed on this page. So please bear with us! <br /></div>
                        On this page you can find all of our users Twitter accounts in one useful page, feel free to follow who you like the look off.<br />
                        We made this page as an extra feature, so it makes it easier to follow people!<br />
                        <strong>'.$user_info['oauth_uid'].'</strong>
                        <hr>
                        <div class="twitterInfo2">In order for you to appear on this page you need to authenticate your twitter account by clicking below! <br /></div>
                        <a href="/twitter/process.php"><img src="/twitter/images/sign-in-with-twitter.png" width="151" height="24" border="0" /></a>
                        <hr>
                    </div>
                        <div class="4u">
                        <a class="twitter-timeline" data-dnt="true" href="https://twitter.com/TubeNations" data-widget-id="635542971107143680">Tweets by @TubeNations</a>
                        </div>
            </div>';
        }
            else
            {
                echo '
            <div class="row">
                    <div class="8u">                    
                        <br />
                        <div class="twitterInfo2">IMPORTANT ANNOUNCEMENT: We are currently trying to setup a twitter authentication system, so that users have to authenticate their twitter accounts 
                        in order for them to be displayed on this page. So please bear with us! <br /></div>
                        On this page you can find all of our users Twitter accounts in one useful page, feel free to follow who you like the look off.<br />
                        We made this page as an extra feature, so it makes it easier to follow people!<br />
                        <hr>
                        <div class="twitterInfo2">You have already linked your twitter! <strong>'.$user_info['oauth_uid'].'</strong><br /> </div>
                        <hr>';
            echo getTwitterInfo();          
            echo '      </div>
                        <div class="4u">
                        <a class="twitter-timeline" data-dnt="true" href="https://twitter.com/TubeNations" data-widget-id="635542971107143680">Tweets by @TubeNations</a>
                    </div>
            </div>';
            }
            echo '</div>';
        }

我尝试了许多不同的组合,但都失败了......如果我缺少您需要的更多代码或信息,请告诉我

我设法自己解决了。 所以我想我会发布我自己的答案:)

所以我基本上使用了其他函数中的一个变量,并在下面的过程中使用了这个.php文件。

user->data['user_id'] 

然后,我将user_id行移动到sql users表中的末尾,并且还在函数.php文件中的每一行末尾添加了所有额外的SQL插入

user_id = '".$tn_userid."'

然后为了解决 Twitter 页面的问题,我创建了一个函数来从 users 表中获取数据:

function getUserTwitterInfo($id){
$mysqli = db_connect();
$query = "SELECT * FROM `**HIDDEN**`.`users` WHERE `user_id`= ? ";
if (mysqli_connect_errno()) {
    printf("Connect failed: %s'n", mysqli_connect_error());
    exit();
}
$id = mysqli_real_escape_string($mysqli,$id);
if ($stmt = $mysqli->prepare($query)){
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($myrow = $result->fetch_assoc()) {
        $user_info = $myrow;
    }
    $stmt->close();
}
$mysqli->close();
return $user_info;

然后我只是在推特页面上宣布了它:

if ($user_login == 1){
echo '<h1 class="icon fa-twitter"> Twitter Page!</h1>';
    #$user_id = intval($user->data['user_id']);
    include "twitter/includes/functions.php";
    $id = $phpbb_user_id;
    $user_info = getUserTwitterInfo($id);
    #echo $oauth_uid;
    if ($user_info['user_id'] == 0)
        {
            echo '

我现在很高兴,我设法做到了:)有点可惜我没有收到答案:(