Google Wave已经公测一个月了,再全世界范围内都掀起了一股索要Google Wave的热潮。做为一个有思想的程序员,除了为Google Wave自身的新特性感动兴奋和赞叹以外, 我们还好奇Google Wave 提供的API能干些什么。
说一句题外话:Google Wave计划引入类似IPhone的应用商店(AppStore)的模式,提高开发着的积极性,为开发者带来收入。嘿嘿,所以无论从兴趣上,还是从现实上,研究开发Google Wave的第三方应用都是有价值的! o(∩_∩)o
如果您没有接触过Google Wave,流牛木马在这里推荐您先阅读这两个网页,再来看流牛木马的开发讲解。
关于Google Wave是什么: Google Wave,新Web时代的沟通平台(多图,视频)
关于Google Wave能干什么: Google Wave试用体验与Google的野心
如果您已经了解完Google Wave的基础,OK,我们开始吧。
Google Wave API能干什么?
Google Wave 各种API的开发示例
from waveapi import events
from waveapi import model
from waveapi import robot
def OnParticipantsChanged(properties, context):
"""当参与者发生变化时,执行的函数"""
added = properties[‘participantsAdded‘]
for p in added:
Notify(context)
def OnRobotAdded(properties, context):
"""当机器人刚被添加时,执行的事件"""
root_wavelet = context.GetRootWavelet()
root_wavelet.CreateBlip().GetDocument().SetText("我是机器人,我开始工作了!")
def Notify(context):
root_wavelet = context.GetRootWavelet()
root_wavelet.CreateBlip().GetDocument().SetText("有新朋友来了!")
if __name__ == ‘__main__‘: """为这个机器的属性(profile)赋值。分别是:机器人名称、机器人头像、版本号、地址"""
myRobot = robot.Robot(‘appName‘,
image_url=‘http://appName.appspot.com/icon.png‘,
version=‘1‘,
profile_url=‘http://appName.appspot.com/‘) """以下是添加Handler,对[参与者变化]和[机器人添加]这两个事件赋予相应的处理函数。"""
myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged)
myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
myRobot.Run()
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="State Example" height="120">
<Require feature="wave" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<div id="content_div" style="height: 50px;"></div>
<script type="text/javascript">
var div = document.getElementById(‘content_div‘);
//用户点击按钮时, 在本wave中获取到[count]变量的值,加1,记录。
function buttonClicked() {
var value = parseInt(wave.getState().get(‘count‘, ‘0‘));
wave.getState().submitDelta({‘count‘: value + 1});
}
//当状态变更时,在wave中获取到[count]变量的值,并显示。如果[count]变量不存在,显示为0.
function stateUpdated() {
if(!wave.getState().get(‘count‘)) {
div.innerHTML = "The count is 0."
}
else {
div.innerHTML = "The count is " + wave.getState().get(‘count‘);
}
}
//初始化:判断这个Gadgets是不是包含在Wave的容器内,如果是则进行初始化。
function init() {
if (wave && wave.isInWaveContainer()) {
wave.setStateCallback(stateUpdated);
}
}
gadgets.util.registerOnLoadHandler(init);
//重置[count]变量的值为0
function resetCounter(){
wave.getState().submitDelta({‘count‘: ‘0‘});
}
</script>
<input type=button value="Click Me!" id="butCount" onClick="buttonClicked()">
<input type=button value="Reset" id="butReset" onClick="resetCounter()">
]]>
</Content>
</Module>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Wave Embed API Example: Simple Wave</title>
<script src="http://wave-api.appspot.com/public/embed.js" type="text/javascript"></script>
<script type="text/javascript"> //寥寥数行,就把一个已有的Wave插入到了某网页的一个叫做"waveframe"的div中
function initialize() {
var wavePanel = new WavePanel(‘http://wave.google.com/a/wavesandbox.com/‘);
wavePanel.loadWave(‘wavesandbox.com!w+waveID‘);
wavePanel.init(document.getElementById(‘waveframe‘));
}
</script>
</head>
<body onload="initialize()">
<div id="waveframe" style="width: 500px; height: 100%"></div>
</body>
</html>
这里是DEMO页 : http://file2.ws/hosted/2/53472/1.htm ,不过前文说了,现在Wave处于半公测阶段,您需要Google Wave的开发者帐号才能看到哦!
怎么样,很简单吧? 呵呵, 赶快一起投入到Google Wave的开发当中吧!
如果您有一些好的创意,尤其是关于Robots与Gadgets的,请告诉我,我非常有兴趣与大家一起探讨。o(∩_∩)o
转载请著名版权: 流牛木马 @ 博客园
本文地址: http://www.cnblogs.com/azure/archive/2009/11/13/GoogleWaveAPI.html
讲师:don 浏览数:17