Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何保存Tumblr OAuth密钥,以便用户不必授权每个会话?_Php_Mysql_Session_Oauth - Fatal编程技术网

Php 如何保存Tumblr OAuth密钥,以便用户不必授权每个会话?

Php 如何保存Tumblr OAuth密钥,以便用户不必授权每个会话?,php,mysql,session,oauth,Php,Mysql,Session,Oauth,我的实用程序文件中有一个连接到tumblrapi的函数,它应该从MySQL数据库中提取OAuth数据,但我不知道该怎么做,因为它不起作用。我遇到的主要问题是试图用数据库中的令牌和机密替换$\u会话['t']和$\u会话['s']变量 实用程序文件函数(util.php): $consumerKey = 'XXX'; $consumerSecret = 'XXX'; $client = new Tumblr\API\Client($consumerKey, $consumerSecret)

我的实用程序文件中有一个连接到tumblrapi的函数,它应该从MySQL数据库中提取OAuth数据,但我不知道该怎么做,因为它不起作用。我遇到的主要问题是试图用数据库中的令牌和机密替换
$\u会话['t']
$\u会话['s']
变量

实用程序文件函数(util.php):

$consumerKey = 'XXX';
  $consumerSecret = 'XXX';
  $client = new Tumblr\API\Client($consumerKey, $consumerSecret);
  $requestHandler = $client->getRequestHandler();
  $requestHandler->setBaseUrl('https://www.tumblr.com/');

  function tumblrAuth($verifier) {
    global $client;
    global $requestHandler;
    global $user;
    global $con;
    global $consumerKey;
    global $consumerSecret;

    // use the stored tokens
    $client->setToken($_SESSION['t'], $_SESSION['s']);

    // to grab the access tokens
    $resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $verifier, 'oauth_token' =>));
    $out = $result = $resp->body;
    $data = array();
    parse_str($out, $data);

    // store our token and secret
    $token = $data['oauth_token'];
    $secret = $data['oauth_token_secret'];

      // we should probably put the token and secret in the database
      $s = "UPDATE user SET tumblr_token='$token', tumblr_secret='$secret', tumblr_verifier='$verifier' WHERE id='$user->id';";

      if($q = $con->query($s)) {
        // and prove we're in the money
        $client = new Tumblr\API\Client($consumerKey, $consumerSecret, $token, $secret);
        return $client;
      } else {
        // failed
        echo "Failed to update token and secret.";
        return false;
      }
  }
回调(tumblr\u auth.php)

require_once'include/util.php';
//如果我们是第一次来
如果(!isset($\u GET['oauth\u verifier'])){
//获取oauth令牌
$resp=$requestHandler->request('POST','oauth/request_-token',array());
$out=$result=$resp->body;
$data=array();
parse_str($out$data);
//告诉用户去哪里
回声';
$\u会话['t']=$data['oauth\u令牌'];
$\u会话['s']=$data['oauth\u令牌\u密码];
}否则{
if($tumblr=tumblrAuth($\u GET['oauth\u verifier'])){
标题(“位置:.$site_index”);
}
}
我也试过使用

我怎样才能做到这一点

require_once 'include/util.php';

  // If we are visiting the first time
  if (!isset($_GET['oauth_verifier'])) {

      // grab the oauth token
      $resp = $requestHandler->request('POST', 'oauth/request_token', array());
      $out = $result = $resp->body;
      $data = array();
      parse_str($out, $data);

      // tell the user where to go
      echo '<a href="https://www.tumblr.com/oauth/authorize?oauth_token=' . $data['oauth_token'].'"> GO </a>';
      $_SESSION['t']=$data['oauth_token'];
      $_SESSION['s']=$data['oauth_token_secret'];

  } else {
      if($tumblr = tumblrAuth($_GET['oauth_verifier'])) {
        header("Location:".$site_index);
      }
    }