我正在使用 twitteroauth.php 使用 twitter api 向我的网站添加登录功能。
它工作正常。但我想使用 jQuery 和 AJAX 来实现相同的功能,这样页面就不会在返回时刷新。
以下是我的一段代码
<?php
require("twitter/twitteroauth.php");
require 'config/twconfig.php';
session_start();
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://list.2lessons.com/fbtwLogin/getTwitterData.php');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
if ($twitteroauth->http_code == 200) {
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
header('Location: ' . $url);
} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
die('Something wrong happened.');
}
?>