TwitterOAuth-在MySql中存储令牌
我正在使用Twitter OAuth类连接到此处找到的Twitter: 目前该脚本只使用提供的令牌,但不将它们存储在数据库中,我希望该脚本能够做到这一点 这是我当前在回调脚本中的内容:TwitterOAuth-在MySql中存储令牌,mysql,oauth,twitter,Mysql,Oauth,Twitter,我正在使用Twitter OAuth类连接到此处找到的Twitter: 目前该脚本只使用提供的令牌,但不将它们存储在数据库中,我希望该脚本能够做到这一点 这是我当前在回调脚本中的内容: <?php /** * @file * Take the user when they return from Twitter. Get access tokens. * Verify credentials and redirect to based on response from Twitter
<?php
/**
* @file
* Take the user when they return from Twitter. Get access tokens.
* Verify credentials and redirect to based on response from Twitter.
*/
/* Start session and load lib */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
/* If the oauth_token is old redirect to the connect page. */
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
$_SESSION['oauth_status'] = 'oldtoken';
header('Location: ./clearsessions.php');
}
/* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
/* Request access tokens from twitter */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
/* Save the access tokens. Normally these would be saved in a database for future use. */
$_SESSION['access_token'] = $access_token;
/* Remove no longer needed request tokens */
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
/* If HTTP response is 200 continue otherwise send to connect page to retry */
if (200 == $connection->http_code) {
/* The user has been verified and the access tokens can be saved for future use */
$_SESSION['status'] = 'verified';
header('Location: ./index.php');
} else {
/* Save HTTP status for error dialog on connnect page.*/
header('Location: ./clearsessions.php');
}
您需要的数据存储在$\u会话['access\u token']=$access\u token代码>变量
尝试print\r($access\u token)代码>
在该变量中,您将发现:
screen_name
user_id
oauth_token
oauth_token_secret
可用于应用程序并存储在数据库中