duanniesui6391 2012-01-10 13:24
浏览 28
已采纳

如何使用php和cUrl安排墙贴

I managed to post a status to my wall with a custom app, but what I want to do, is schedule the status, to be posted on a given datetime.

The problem was, when I close my app, the script is aborted. Right now it works, I'm using ignore_user_abort(true) and sleep().

I'm also using set_time_limit(1), once the given datetime has passed, so the script stops.

I feel like this is crappy coding and want to know if there's a better way to do this?

Here's the code I'm using right now:

<?php
 ignore_user_abort(true);
 $token=$_GET["access_token"];
 $attachment =  array(
    'access_token' => "$token",
    'message' => "deze post moet om 14.14 online komen",
    'name' => "testpost",
    'link' => "http://myurl.be/",
    'description' => "Write here your description",
    'picture'=> "http://myurl/assets/images/layout/logo.png");

date_default_timezone_set('Europe/Belgrade');
$time= date('d/m/Y H:i');
if ("10/01/2012 14:14" < $time ){
set_time_limit(1);
$result = $facebook->api('/me/feed/','post',$attachment);
}else{
sleep(60);
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "https://www.myurl.com/tests/facebooklogin/post.php?access_token=".$token);
curl_exec ($curl);
curl_close ($curl);
}  
print $result;
?>
  • 写回答

1条回答 默认 最新

  • duanfan5012 2012-01-10 13:36
    关注

    You could store all the information needed for your post (text, link, description and so on) in a database (like MySQL), setup a PHP script that get's called periodically by cron and fetches all posts from the database that need to be posted by the time the script get's executed.

    But be aware that access tokens expire after a few hours/a day or when the user changes his password. Unless you don't have a "offline_access" permission, then the token never expires.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路