Cron Job + Twitter [英] Cron Job + Twitter

查看:191
本文介绍了Cron Job + Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Every hour starting from 12:30 (and going on to 1:30, 2:30, etc) my app will post a static tweet. I am currently using themattharris's twitter API. I have a cron job as well.

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

我遇到的问题是,PHP代码工作时,我手动刷新index.php& ;我的cron工作半工作。我从cron工作获得的电子邮件是:

The issue I am having is that the PHP code works when I manually refresh index.php & my cron job semi-works. The email I get from my cron job is:

Error 200

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

What I like to know is, how can I get my cron to work? I do not have any errors in my cron job.

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';
}


推荐答案



Try:

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

这是正确的语法,但是它看起来像在你的代码中,你实际希望从一个页面的响应, t如果使用cron工作。

that is the correct syntax, however it looks like in your code you are actually expecting a response from a page, which won't work if using cron.

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

You could do like you said below and use wget to get the actual URL, or the other option would be to use Curl to actually post and request that URL. If you go with Curl, you would be able to use the standard cron since Curl would actually receive the response.

这篇关于Cron Job + Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆