PHP 使用 Bing API

作者: nick 分类: php 发布时间: 2010-09-28 11:53 ė 6没有评论

首先你要去申请一个 Bing API KEY
申请地址: http://cn.bing.com/developers/

使用方法:

<?php
// Include the Bing API PHP Library
require 'library/BingAPI.php';
 
// Simply start the class with your AppID argumented
$search = new BingAPI('YOUR APPID KEY');
 
 
    $search->query($searchWeb)
           ->setSources('Web') # To use multiple resources simply do ->setSources('Web+Image') , it must match the source type bling.com provides
           ->setFormat('xml')
           ->setOptions(array(
                            'Web.Count' => '20',
                            'Web.Offset' => '0',
                            'Adult' => 'Moderate',
                            'Options' => 'EnableHighlighting'));
 
    // Contains the search
    $results = $search->getResults();
 
    /* To use highlighting features use
    /* $search->setHighlightFormat(
                                "<span class='hl'>",
                                "</span>",
                                $SOURCE_TO_FORMAT
                            );
    */
 
    /* If you don't want to highlight your title use
       $search->resetHighlight($string_containing_bing's title);
    */
 
    /* For advanced cURL Users, setProxy() has been removed, you will utilize $search->setCurlArray(array()); */
 
/* And for developers who constantly lurks in bing forums or other developer forums there is $search->getRequestedQueryURL(); it will retrieve the link you use
   to query bing.com servers. eg. http://api.search.live.net/xml.aspx?AppId=YOUR APPD ID&Query=da&Sources=Image&Image.Count=20&Image.Offset=0&Image.Filters=Size:Small&Adult=Moderate&Options=EnableHighlighting
   Note that it will return THE CURRENT URL.
*/
下载: BingAPI.php

本文出自 传播、沟通、分享,转载时请注明出处及相应链接。

本文永久链接: https://www.nickdd.cn/?p=1088

发表评论

您的电子邮箱地址不会被公开。

Ɣ回顶部