1
嗨,我已經爲鳴叫APITwitter的API給錯誤
使用abraham/twitteroauth
給出了錯誤
其實,Twitter的窗口來詢問許可時,我接受給出的oauth_token和祕密密鑰,但使用的是當我嘗試發佈獲取此錯誤。
我的代碼如下
2檔
<?php
session_start();
require_once 'classes/twitteroauth.php';
define("CONSUMER_KEY", "XXXXXXXXXXXXXXXX");
define("CONSUMER_SECRET", "XXXXXXXXXXXXXXXXXXXXXXX");
if(isset($_SESSION["oauth_token"])){
$ction = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$tweetmsg = 'Hello World, I am tweeting from my own twitter app!';
$result = $ction->post('statuses/update', array('status' => $tweetmsg));
$httpCode = $ction->http_code;
if ($httpCode == 200) {
$resultmsg = 'Tweet Posted: '.$tweetmsg;
}
else {
$resultmsg = 'Could not post Tweet. Error: '.$httpCode.' Reason: '.$result->error;
}
} 其他{ 回聲 「有些該死的錯誤!」 給定; } ?>
第一頁
<html>
<head>
<title>Twitter OAuth via popup</title>
</head>
<body>
<script src="jsjquery.min.js"></script>
<script src="js/jquery.oauthpopup.js"></script>
<script>
$(document).ready(function(){
$('#connect').click(function(){
$.oauthpopup({
path: 'twitter.php',
callback: function(){
alert("successfully Tweetted");
window.location.reload();
}
});
});
});
</script>
<div>
<?php
echo $resultmsg;
?>
</div>
<input type="button" value="Connect with Twitter" id="connect" /><br />
<a href="signout.php">Sign Out</a>
</body>
</html>
第二頁
<?php
session_start();
require_once 'classes/twitteroauth.php';
if(!isset($_SESSION["oauth_token"])){
define("CONSUMER_KEY", "XXXXXXXXXXXXXXXX");
define("CONSUMER_SECRET", "XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken();
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->getAuthorizeURL($request_token);
header('Location:'.$url);
die();
}
?>
<html>
<head>
<title>Share On Twitter</title>
</head>
<body>
<script type="text/javascript">
window.close();
</script>
</body>
</html>
1懷疑我將如何在第一個函數中獲得$ _SESSION ['oauth_token'],$ _SESSION ['oauth_token_secret']? – Harish 2011-02-02 08:27:27