duanqin7791 2013-06-20 21:53
浏览 60

使用twitterOAuth登录脚本

I recently started working with twitteroauth login, which seems to be working in the examples (found here) but not when I amalgamate the redirect.php and callback.php Based on the script below (which is integrated in a bit of login script I've been working on) the second portion works fine (which is based on redirect.php), returning an oauth_token and oauth_verifier, but the first part (based on callback.php) isn't even initiating it seems. Which it should when Twitter redirects the user to the homepage.

Any ideas/suggestions folks?

session_start();
require_once('socialCodes.php');    //where I keep my app ID and Secret
require_once('twitteroauth/twitteroauth.php');

if (isset($_GET['oauth_token'])) {
 $connection = new TwitterOAuth($twAppID, $twAppSec, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $connection->host = "https://api.twitter.com/1.1/";

  $access_token = $connection->getAccessToken($_GET['oauth_verifier']);

    $_SESSION['access_token'] = $access_token;

  unset($_SESSION['oauth_token']);
 unset($_SESSION['oauth_token_secret']);

 if (200 == $connection->http_code) {
        $userAccessToken = $access_token['oauth_token'];
     $userSecretToken = $access_token['oauth_token_secret'];
      $userID = $access_token['user_id'];
      $userName = $access_token['screen_name'];
    }

} else {
    $connection = new TwitterOAuth($twAppID, $twAppSec);
   $connection->host = "https://api.twitter.com/1.1/";

 $request_token = $connection->getRequestToken('myhomepage');

 $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

  switch ($connection->http_code) {
     case 200:
        $url = $connection->getAuthorizeURL($token);
        header('Location: ' . $url); 
        break;
   default:
   echo 'Could not connect to Twitter. Refresh the page or try again later.';
 }
}
  • 写回答

1条回答 默认 最新

  • dougang7521 2013-06-21 16:22
    关注

    Turns out this was a caching issue, and the script now works.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)