<?php
include_once("twitter/library/OAuthStore.php");
include_once("twitter/library/OAuthRequester.php");
// register at http://twitter.com/oauth_clients and fill these two
define("TWITTER_CONSUMER_KEY", "hidden");
define("TWITTER_CONSUMER_SECRET", "hidden");
define("TWITTER_OAUTH_HOST","https://api.twitter.com");
define("TWITTER_REQUEST_TOKEN_URL", TWITTER_OAUTH_HOST . "/oauth/request_token");
define("TWITTER_AUTHORIZE_URL", TWITTER_OAUTH_HOST . "/oauth/authorize");
define("TWITTER_ACCESS_TOKEN_URL", TWITTER_OAUTH_HOST . "/oauth/access_token");
define("TWITTER_PUBLIC_TIMELINE_API", TWITTER_OAUTH_HOST . "/statuses/public_timeline.json");
define("TWITTER_UPDATE_STATUS_API", TWITTER_OAUTH_HOST . "/statuses/update.json");
define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));
// Twitter test
$options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET);
OAuthStore::instance("2Leg", $options);
try
{
$request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST");
$result = $request->doRequest(0);
parse_str($result['body'], $params);
$request = new OAuthRequester(TWITTER_PUBLIC_TIMELINE_API, 'GET', $params);
$result = $request->doRequest();
parse_str($result['body'], $params);
}
catch(OAuthException2 $e)
{
echo "Exception" . $e->getMessage();
}
?>
如何向Twitter发送推文?它成功地执行了请求,因为它返回0,但是如果我想发送推文,我仍然不确定从哪里开始。我是唯一使用此功能的人,我只想从我的网站发送推文,而不是在Twitter上登录。
谢谢。