【问题标题】:sync two table user_id and thanks confirmation to user with twitter oauth同步两个表 user_id 并感谢使用 twitter oauth 向用户确认
【发布时间】:2016-08-21 06:43:07
【问题描述】:

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

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

users 表:此表用于 twitter oauth

ID、user_id、oauth_provider、oauth_uid、username、fname、lname、locale、oauth_token、oauth_secret、图片、创建、修改

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

user_id、用户名、yt_channelTitle、积分、user_email、access_token、refresh_token、channel_id、上传、dailyVotes

twitter oauth functions.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 文件:

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

现在是 twitter.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>';
        }

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

【问题讨论】:

  • 有两种方法可以让 user_id 链接,一种方法是从我尝试过的 phpBB 会话数据中以某种方式获取它,也可以从获取数据中获取从我也尝试过但失败的积分表数据库中,我只是无法实现并正确获取代码:(我是编码新手,我仍在学习,我是一个完全 n00b,但我正在慢慢慢慢地学习更多和越来越多的日子和几周过去了,我不是一个快速学习者。

标签: php mysql twitter oauth twitter-oauth


【解决方案1】:

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

所以我基本上使用了来自其他函数的变量,并在下面的 process.php 文件中使用了它。

user->data['user_id'] 

然后我将我的 user_id 行移到我的 sql 用户表的末尾,并且我还在 functions.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 '

现在我很高兴我设法做到了 :) 有点遗憾,但我没有得到答案 :(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 2017-07-04
    • 2012-04-13
    • 2015-10-13
    • 2021-06-07
    相关资源
    最近更新 更多