gpt4 book ai didi

php - Cron 作业 + 推特

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:41 25 4
gpt4 key购买 nike

从 12:30 开始(一直到 1:30、2:30 等),我的应用程序将每小时发布一条静态推文。我目前正在使用 themattharris 的 twitter API。我也有一个 cron 作业。

30 * * * *   php -q /home1/USER_NAME/public_html/twitter/index.php

我遇到的问题是,当我手动刷新 index.php 和我的 cron 作业半工作时,PHP 代码可以工作。我从 cron 作业中收到的电子邮件是:

Error 200

我想知道的是,如何让我的 cron 工作?我的 cron 作业没有任何错误。

include 'tmhOAuth/tmhOAuth.php';

$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'XXX',
'consumer_secret' => 'XXX',
'user_token' => 'XXX',
'user_secret' => 'XXX',
));

// Bahrain's time zone
date_default_timezone_set ('Asia/Riyadh');

// Set status message
$timezone= date("g:i");
$tweetMessage = "It's now" .$timezone. "in Bahrain";

//Response
$response = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array('status' => $tweetMessage));

//Do something if the request was unsuccessful
if ($response != 200) {
echo 'Error 200';
}

最佳答案

尝试:

30 * * * * /usr/bin/php '/home1/USER_NAME/public_html/twitter/index.php'

这是正确的语法,但在您的代码中看起来您实际上是在期待来自页面的响应,如果使用 cron,这将不起作用。

您可以像下面所说的那样使用 wget 获取实际的 URL,或者另一种选择是使用 Curl 实际发布和请求该 URL。如果您使用 Curl,您将能够使用标准的 cron,因为 Curl 实际上会收到响应。

关于php - Cron 作业 + 推特,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17635897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com