【发布时间】: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