【发布时间】:2011-09-29 21:41:16
【问题描述】:
我有什么: 在 twitter 上创建的 Twitter 应用和在 localhost 上创建的 PHP 应用
我想要的: 仅(!)应用程序帐户通过 twitter API 发布推文/更新状态。 没有 twitter@anywhere,没有用户登录,没有什么花哨的。
我尝试了什么:
https://github.com/abraham/twitteroauth 带有来自 dev.twitter.com 网站的访问令牌,返回
"POST 数据不适用于此 令牌”
或类似的东西。
我在某个网站上找到的代码 sn-p:
// Define credentials for the Twitter account
define('TWITTER_CREDENTIALS', 'username:password');
// Set up CURL with the Twitter URL and some options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com/statuses/update.xml?status=test_status');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Twitter uses HTTP authentication, so tell CURL to send our Twitter account details
curl_setopt($ch, CURLOPT_USERPWD, TWITTER_CREDENTIALS);
// Execute the curl process and then close
$data = curl_exec($ch);
curl_close($ch);
// If nothing went wrong, we should now have some XML data
echo '<pre>'.htmlentities(print_r($data, true)).'</pre>';
返回
"基本认证不 支持”
【问题讨论】: