新浪微博应用开发---AutoDelete

  国外有个应用叫snapchat,阅后即焚,然后我就尝试着做一个微博版的叫做AutoDelete,网址http://snapchat.sinaapp.com/

界面很简陋,其实思路不难:

  1.建一个数据表,字段有,用户的微博id,用户的Token,删除微博的时间

  2,当用户发一条微博后,获取他的微博id,Token,时间,存入数据表中

  3.每个一段时间,访问数据库,看是否需要删除某条微博

注意:没有Token,你是没有权限删除微博的

  源码:

  代码我是托管到SAE上的 

delete.php

<?php
session_start();

include_once( 'config/config.php' );
include_once( 'config/saetv2.ex.class.php' );

//$c = new SaeTClientV2( WB_AKEY , WB_SKEY ,'2.00d4EJHD0VWUn20d6c64753a0QNrPk' );
//$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
//include_once('test.php');
   $link=mysql_connect("xxxxxxxxxxxxxx","xxxxxxxxx","xxxxxxxxxxxx");//换成自己的
    mysql_query("SET NAMES utf8");
    mysql_select_db("app_snapchat",$link);
	$time=time()+30;
 	$query="select * from snapchat_info where time<$time";
	$result=mysql_query($query);
    while($row=mysql_fetch_assoc($result))
    {
         $token=$row['token'];
        // $c = new SaeTClientV2( WB_AKEY , WB_SKEY ,'2.00d4EJHD0VWUn20d6c64753a0QNrPk');
        $c = new SaeTClientV2( WB_AKEY , WB_SKEY ,$token);
        $ret=$c->delete($row['id']);//删除微博
        //$delete_query="delete from snapchat_info where id=$row['id']";
        //mysql_query($delete_query);
        echo $row['id']."<br/>";
        echo $ret['error']."<br/>";
        echo $token;
    }
   mysql_close($link);
?>

weibo.php

<?php
session_start();

include_once( 'config/config.php' );
include_once( 'config/saetv2.ex.class.php' );


$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$ms  = $c->home_timeline(); // done
$uid_get = $c->get_uid();
$uid = $uid_get['uid'];//获得ID
$user_message = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息
$user_weibo=$c->user_timeline_by_id();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <link href="css/send.css" rel="stylesheet" type="text/css" />
      <link href="css/alert.css" rel="stylesheet" type="text/css" />
   
<title>定时删除你的微博,不留痕迹</title>
</head>
    <body>
      
     <div class="send_info">
         <?=$user_message['screen_name']?>,您好! 
        </div>
      <div class="send_content">
       <form action="" method="post">
           <textarea name="text" rows="30" cols="30" class="send_text"></textarea><br/>
           <input type="text" class="send_time" name="delete_time">
           <div class="send_desc">分钟后,自动删除</div>
           <input type="submit" class="u-btn send_button" value="发布">
        </form>
       </div>
<?php
if(isset($_REQUEST['text'])) {
    $ret = $c->update( $_REQUEST['text'] );	//发送微博
	if ( isset($ret['error_code']) && $ret['error_code'] > 0 ) {
		echo "<p>发送失败,错误:{$ret['error_code']}:{$ret['error']}</p>";
	} else {
        //echo "<p>发送成功</p>"+$ret['id'];
       echo "<div class=\"m-layer z-show\"><table><tbody><tr><td>
    <article class=\"lywrap\">
	    <section class=\"lyct\">
	        <p>发表成功,等待刷新</p>
	    </section>
    </article></td></tr></tbody></table>
</div>
";
     echo "<script type='text/javascript'>document.location.href='http://snapchat.sinaapp.com/test.php'</script>";
    }
     $ret_id=$ret['id'];//微博ID
    $time=time();//发送微博的时间
    $delete_time=$_REQUEST['delete_time']*60+$time;  
    $token=$_SESSION['token']['access_token'];
    $text=$_REQUEST['text'];
    
$link=mysql_connect("xxxxxxxxxxxxxx","xxxxxxxxx","xxxxxxxxxxxx");//换成自己的
mysql_query("SET NAMES utf8"); mysql_select_db("app_snapchat",$link); $query="insert into snapchat_info(num,id,text,token,nowtime,time) values('','$ret_id','$text','$token','$time','$delete_time')"; mysql_query($query); // $sql=mysql_query("insert into 'snapchat_info' (num,id,time) values('','4','2')",$link); mysql_close($link); // $ret=$c->delete(3590318362743084); }?><!---------------------------------------------------><?php if( is_array( $user_weibo['statuses'] ) ): ?><?php foreach( $user_weibo['statuses'] as $item ): ?> <div class="weibo_list"><div class="weibo_content"><?=$item['text'];?></div> <div class="weibo_time">---<?=$item['created_at'];?></div> </div> <?php endforeach; ?><?php endif; ?> </body></html>
config.yaml

name: snapchat
version: 1
accesskey: j2o2ly5moj
cron:
    - description: test1
	  url: delete.php
	  schedule: every 6 mins
	  timezone: Beijing
我的是每隔六分中更新下


代码很乱,大家可以重构下


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值