<?php
// Set username and password
$username = 'XXX';
$password = 'XXX';
// The message you want to send
$message = 'is twittering from php using curl';
// The twitter API address
$url = 'https://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'https://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'failure';
} else {
echo 'success';
}
echo $buffer;
?>
你好,我上面的代碼有問題。我從一個網站上得到它。它在 $buffer 處回傳,服務器理解該請求,但它是一個被禁止的請求。
uj5u.com熱心網友回復:
Twitter API 不支持使用用戶名和密碼發送推文,您需要使用 OAuth。此外,您在此代碼中使用的 Twitter API URL 非常舊(例如,大約 14 歲)。您需要使用官方 Twitter API。有一些當前可用的 PHP 庫。
uj5u.com熱心網友回復:
它可能在您服務器的組態檔中被禁用。您應該查看您的特定服務器設定并擺弄,curl_exec默認情況下可能已禁用。
您可以使用以下命令檢查該設定是否已啟用;
<?php phpinfo(); ?>
如果您在配置php.ini檔案方面需要幫助,請查看此主題;在 php.ini 上啟用 curl_exec。您將不得不尋找帶有disabled_functions,的行,curl_exec可能會添加到那里。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/324920.html
上一篇:SQLSTATE[42000]:語法錯誤或訪問沖突:1068定義了多個主鍵
下一篇:將請求作為日期
