我已经开始查看 twitter php 库http://github.com/abraham/twitteroauth,但我无法让它在我的 ubuntu 服务器上运行,但在我的 mac 上,使用 mamp 它可以正常工作。
这是不会在我的服务器上运行的代码,但在 mamp. 是的,我有编辑配置文件
<?php
/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
case 200:
/* Build authorize URL and redirect user to Twitter. */
$url = $connection->getAuthorizeURL($token);
header('Location: ' . $url);
break;
default:
/* Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';
}
我在我的 ubuntu 服务器上启用了 php 会话,因为这段代码有效
<?php
session_start();
$_SESSION["secretword"] = "hello there";
$secretword = $_SESSION["secretword"] ;
?>
<html>
<head>
<title>A PHP Session Example</title>
</head>
<body>
<?php echo $secretword; ?>
</body>
</html>