gpt4 book ai didi

mysql - Twitter OAuth - 在 MySql 中存储 token

转载 作者:可可西里 更新时间:2023-11-01 06:46:23 25 4
gpt4 key购买 nike

我正在使用 Twitter OAuth 类连接到此处的 Twitter:

目前脚本只使用提供的 token ,但没有将它们存储在数据库中,我希望脚本能做到这一点。

这是我目前在回调脚本中的内容:

<?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');
}

如何将 token 保存到 MySql,在脚本的哪一部分获取 token ?

最佳答案

您需要的数据存储在 $_SESSION['access_token'] = $access_token; 变量中。

试试 print_r($access_token);

在那个变量中你会发现:

screen_name
user_id
oauth_token
oauth_token_secret

可用于您的应用程序并存储在您的数据库中。

关于mysql - Twitter OAuth - 在 MySql 中存储 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3531744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com