PHP Plurk Api基�教�(一)

简介:这是PHP Plurk Api基�教�(一)的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=346948' scrolling='no'>

PHP Plurk Api基�教�(一) - 如何�作自��噗�器人

1.第一步

到Plurk PHP APi Google code官�下�最新的PHP API

上面的��是1.6.2版(��已�是最�版了)

未�噗浪要改用http://www.plurk.com/API/2/ �似FB的API方式

2.下�後解��在webserver�料��,打��料��的php-plurk-api的example.php,我�直接用�例��修改

3.先把�面�容全�掉,精�成以下程式�:

<?php
$api_key = ''; //你的Plurk api key
$username = ''; //你的Plurk��
$password = ''; //你的Plurk密�

require('plurk_api.php');

$plurk = new plurk_api();
$plurk->login($api_key, $username, $password);
?>

4.到Plurk APi官�申�一�Plurk api key

到下方的Get an api key填�料 取得

api key�寄到你的信箱 再把他填入$api_key�面

到�一步基本上你已�完成基�的"PHP API登入"作�了,再�要�如何�噗!

5.如何使用PHP API�噗?

�入以下程式�,�於��器中�行:

<?
$plurk->add_plurk('zh-tw','says','大家好啊!');
?>

你���,你的噗浪上多一�"says:大家好啊!"的�息

但是你在重��行一次��就�有了,因�噗浪有防洪�制,同��容的噗不能一直�

6.�作:�用��判�和�料�,�作早晚�安噗�器人:

Mysql�料表��:

�料�名�(自�): _plurk

�料表名�(自�): _talk

�料表�位: 一��位 型�int �度255 命名成(自�):_time 

程式部分:

後台�行�(example.php):

<?
mysql_connect("localhost","root","123");//�接�料�
mysql_query("set names 'utf8'");//�定��UTF-8
mysql_select_db("_plurk");//���料�

date_default_timezone_set("Asia/Taipei");//�定����洲/台北GMT+8

$now_time = date("U",mktime(date("H"),0,0,date("m"),date("d"),date("Y")));
//取的今天�在的�秒�
$now_hour = date("G");//取的今天�在的小�
$have_post=@mysql_result(mysql_query("select * from _talk where _time='$now_time' "),0,"_time");//看看�料��是否已�有噗�的��,避免重噗��
if($have_post=="")//如果等於空就是�有噗�,所以�有��
{

switch($now_hour) //看�在是��就噗什�!
{
case 7: $post = "早起的��有�吃"; break;
case 23: $post = "夜深了,早�睡吧";break;
}

$plurk->add_plurk('zh-tw','says',$post);//�噗
mysql_query("insert into _talk(_time) values('$now_time')")//�入�料���
}
?>

我�知道PHP是伺服器端�言,所以不�有��,至於�如何�程式自�跑呢?,就得藉由Javascript Ajax�助

程式前端(index.php):

<!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" />
<title>PHP PLURK API Autorun</title>

<script language="javascript" src="./jquery-1.5.js" type="text/javascript"></script>

</head>
<body>

<script language="javascript">
var total=0;
function rload()
{
$("#at").html("Loading...");
total++;
$.get(
"./example.php",
{rand:Math.random()},
function(data)
{
$("#at").html("example.php程式已�行了<u>"+total+"</u>次");
rload();
},
"html"
)
}
$(document).ready(function(){
rload();
});
</script>

<div id="at">

</div>

</body>
</html>

�用Jquery的Ajax�行重��行,�自行到Jquery官�下�Jquery的JavaScript�充程式�放在同一�料�下

�用以上��方式 程式�自�重新�行,只要��停留在index.php��,�器人就�自�在指定���噗�行!

下次再PO��的用法...

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/346948.html pageNo:4

posted on 2011-11-08 07:54  圣者  阅读(745)  评论(0编辑  收藏  举报

导航