作者: Navneet Behal
当 SOAP的来临和 XML等相似的到来一样 , 站点开发者可以非常轻易的从不同的来源提供其他站的更多信息。 为了增加这种方便,许多不同的Web服务提供了API,诸如Google, Amazon, ebay 以及一些你所知道的名字。
Google作为我最喜爱的搜索引擎(以及数百万个互联网网用户的), Flash是我的生计工具,这个想法就是建立一个环境可以使Flash能使用Google并且在该Flash中输出结果。
基本需求:我们需要以下东西建立这个产品
Flash MX PHP 并有XML支持 Nusoap(PHP小组一种,答应开发者建立使用 SOAP网页服务) A Google API 账户(可以在这里获得) 我在这里将不打算介绍SOAP的细节以及如何使用它。在线帮助已经有足够的数据了。无论如何,对XML和它的各种各样的同胞的熟悉是我从读者那里期望的全部。无论如何,我期望读者们能够阅读它。 不过,通过Nusoap 访问Google之后我将大力推荐在Devshed上的这篇文章。制作步骤
第一步,建立一个PHP文件连接到Google,并在Flash环境中获得搜索结果。下面是该文件的原代码。 这个过程很轻易使用Nusoap实现。
//Initialize PHP
//include the nusoap class..(http://dietrich.ganx4.com/nusoap/)
include_once($DOCUMENT_ROOT."/../scripts/nusoap/nusoap.php");
/*prints the results of the search in a swf file
as an array structure to hold ready made data for flash*/
function google2Flash($searchStr,
$startParam=0){
if(empty($searchStr))
{
expirationHeaders();
return;
}//end if
// create an instance of the SOAP client object
// remember that this script is the client,
// accessing the web service provided by Google
$soapclient =
new soapclient("http://api.google.com/search/beta2");
setType($startParam,
"integer");
$maxResults =
10; //Google
Limit :(
// set up an array containing input parameters to be
// passed to the remote procedure
$params =
array(
"key"
=> "xxxxxxxxxxxxxxx",//
Google license key
"q"=>
$searchStr,//
search term..given by flash user
"start"
=> $startParam*$maxResults,
// start from result n
"maxResults"
=> $maxResults,//
show a total of n results.. Google Limit 10
"filter"
=> false,//
remove similar results
"restrict"
=> "",//
restrict by topic
"safeSearch"
=> false,//
adult links?
"lr"
=> "",//
restrict by language
"ie"
=> "",//
input encoding
"oe"
=> ""//
output encoding
);
// invoke the method on the
server
$result =
$soapclient->call("doGoogleSearch",
$params, "urn:GoogleSearch",
"urn:GoogleSearch");
//Now result will be an
array which contains various result elements
//it is these elements that we are concerned with
$tElements =
sizeof($result["resultElements"]);
if(empty($tElements))
{
expirationHeaders();
return;
}//end if
//Send expiration headers
expirationHeaders();
//Okay so we got
something.. now we have to make a display string for Flash
文章地址: http://www.xinasp.com/html/wangzhanyunying/yumingxinwen/20061005/32251.shtml
tag:Flash 进行 Google


RSS订阅
评论加载中…



