搜索引擎优化

搜索引擎优化

SEO文库

搜索引擎优化 | Google优化 | 搜索引擎界 | SEO动态 | SEO工具 | SEO资料 | 互联网观察 | SEO查询 | 搜索引擎免费登录

产品服务

  搜索引擎优化(SEO)服务  |  搜索引擎营销(SEM)服务  |  网络营销策划服务  |  大型网站咨询服务 关于我们  |  咨询

本站推荐

dmoz.org的网站选择标准
Google发现的十大真理
Google技术
CSS2.0中文手册查阅
深入Yahoo!
web2.0网站集合

热门文章

搜索引擎及目录免费登录入口
如何提高网站的Google PR值
搜索引擎优化(SEO)服务
dmoz.org的网站选择标准
Google Sitemap更快更全面收录网站
为什么要使用html的meta标签?

产品服务

搜索引擎营销(SEM)服务
网络营销策划服务
大型网站咨询服务
搜索引擎优化(SEO)服务
网站评估和优化诊断

客户推广

水处理设备
china flowers
china florist
视频会议
air compressor
空压机
酒店管理软件
china valve
翻译公司
主页 > se新闻

用Flash 进行Google

来源地: product beta 更新时间:2005-9-27 浏览次数:

演示:http://www.productbeta.com/google/index.php

当 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实现。
  <?php
   //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
   print "&displayData=";
   for($i=0; $i<$tElements; $i++){
   //If we got a title the this result..
   if (!empty($result["resultElements"][$i]["title"])){
   //If no link available
   if (empty($result["resultElements"][$i]["URL"])){
   print "<font size=\"12px\"><b>".(($i+1) + ($startParam*$maxResults)).". ".urlencode($result["resultElements"][$i]["title"])."</b></font>";
   } else {
   print "<font size=\"12px\"><b>".(($i+1) + ($startParam*$maxResults)).". </b><a href=\"".urlencode($result["resultElements"][$i]["URL"])."\" target=\"_blank\"><b><u>".urlencode($result["resultElements"][$i]["title"])."</u></b></a></font>";
   }//End if
   print "<br><br>";
  
   //Did we get a summary?
   if(!empty($result["resultElements"][$i]["summary"])){
   print "<font size=\"10px\"><b>Summary</b>: ".urlencode(ereg_replace("\n|<br>", "", $result["resultElements"][$i]["summary"]))."</font><br>";
   }//End if
  
   //Did we get a snippet?
   if(!empty($result["resultElements"][$i]["snippet"])){
   print "<font size=\"10px\">".urlencode(ereg_replace("\n|<br>", "", $result["resultElements"][$i]["snippet"]))."</font><br>";
   }//End if
  
   print "-----------------------------------------------------------------------------";
  
   //if we are not on the last element.. print a break
   if($i+1 < $tElements){
   print "<br><br>";
   }//End if
   }//End if
   }//End for loop
  
   //Print out the total results number that came in
   print "&estimatedTotalResultsCount=".$result["estimatedTotalResultsCount"]."&";
   //Calculate the total number of pages which will be needed to show all the results
   print "&tPages=".ceil($result["estimatedTotalResultsCount"]/$maxResults)."&";
   print "&searchTime=".urlencode($result["searchTime"])."&";
   print "&searchQuery=".urlencode($result["searchQuery"])."&";
   }//End function
  
   //Prints an expiration headers for form-encoded data
   function expirationHeaders(){
   header("application/x-www-urlform encoded");
   header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); //Creation time
   header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); //Expiration time.. right away!
   header("Cache-Control: no-cache, must-revalidate");
   header("Pragma: no-cache");
   }//End function
  
   google2Flash(urldecode($usrInput), $startParam);
  
   //Goodbye PHP
   ?>

  这里是PHP代码的一些难点:

包含Nusoap
传送用户输入和开始的数据(在脚本中还有数据是Flash本身工作的传输)定义google2Flash的PHP功能 。
google2Flash将做如下工作:
连接到Google (使用 nusoap)
在Google使用Flash传送数据执行一个搜索...需要使用Google API组件执行GoogleSearch
传送头部数据确认数据正确到达。
输出Google结果列表数据或其他数据量,发回到Flash并准备显示。Google每一次提交将仅仅提供最大十个数据量,这是Google API极限,不是我的错。Flash需要输出至少50个吧这样你会觉得更需要些。
  在选择可能在Flash返回“准备成功的”显示数据和Flash传递数据组列并分析两者之间,我选择了前者,因为我并不满意 actionscript处理一大堆数据 的速度。在一些PHP工作会比 actionscript快点,它还可以重定义数据显示的样子并不需要产生任何文件,在Flash里执行就可以了,这样方便不少。

  进行 Flash制作!

  我将设计部分留给了你, 我自己制作的布局并不复杂只是想完成Flash引用Google搜索的过程。本质上,这些Flash的应用是使用loadVars() 组件。
  这里是在Flash(通过PHP)从Google获得数据的核心部分。工程的整个代码是比较复杂将需要更多页码的教程在OOP 设计上,我们将跳过这个。

  /*############################
  GOOGLE SEARCH ENGINE
  #############################*/
  Google = new Object();
  Google.submitSearch = function(){
//Create loadvars object
this.googleData = new LoadVars();
this.googleData.usrInput = this.searchBox.inputFieldMc.usrInput.text;
this.googleData.startParam = this.startParam;

this.googleData.onLoad = function(){
//We did get some results
if(typeof(this.displayData) != "undefined"){
_level0.Google.resultsBox.resultArea.results.htmlText = this.displayData;
delete(this.displayData); //Delete this really long string!
}//End if

this.googled = true; //Indicator that we are done with onLoad method
}//end function
this.googleData.sendAndLoad("/google/scripts/getGoogle.php", this.googleData, "POST");
  }//End function


【声明】:
  以上文章或资料除注明为SEO165.COM自创或编辑整理外,均为各方收集或网友推荐所得。其中摘录的内容以共享、研究为目的,不存在任何商业考虑。
  目前网站上有些文章未注明作者或出处,甚至标注错误,此类情况出现并非不尊重作者及出处网站,而是因为有些资料来源的不规范。如果有了解作者或出处的原作者或网友,请告知,本网站将立即更正注明,并向作者或出处单位道歉。
  被摘录的对象如有任何异议,请与本站联系,联系邮箱:seo165@gmail.com,本站确认后将立即撤下。谢谢您的支持与理解!
 

公司介绍   联系我们   留言   地图   SEO   免费登录   Google排名   搜索引擎大全   网站优化   网站推广   工具条  
Copyright 2004-2008 上海尚东科技有限公司   上海·北京china seo 版权所有 Contact webmaster.   未经本站允许镜像或者盗链的网站将受法律责任!