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 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算