【问题标题】:fail to use web service with php无法通过 php 使用 Web 服务
【发布时间】:2012-01-23 17:09:03
【问题描述】:

我使用这个网站作为我的网络服务的指南..

http://developer.yahoo.com/answers/V1/questionSearch.html

我使用这个代码:

$client=new SoapClient("http://answers.yahooapis.com/AnswersService/V1/questionSearch");
$resposeArray=$client->__call("query","economics");

var_dump($resposeArray);

显然,我无法检索任何内容.. 并收到此错误:

致命错误:未捕获的 SoapFault 异常:[WSDL] SOAP-ERROR:解析 WSDL:无法从“http://answers.yahooapis.com/AnswersService/V1/questionSearch”加载:无法加载外部实体“http ://answers.yahooapis.com/AnswersService/V1/questionSearch" 在 C:\xampp\htdocs\Unnamed Site 2\untitled1.php:11 堆栈跟踪:#0 C:\xampp\htdocs\Unnamed Site 2\untitled1。 php(11): SoapClient->SoapClient('http://answers....') #1 {main} 在 C:\xampp\htdocs\Unnamed Site 2\untitled1.php 第 11 行抛出

【问题讨论】:

    标签: php web-services soap yahoo-api


    【解决方案1】:

    要使 web 服务与您的代码一起工作,PHP 必须能够获取外部文件:

    http://answers.yahooapis.com/AnswersService/V1/questionSearch
    

    但是该文件不再起作用并返回错误:

    HTTP/1.1 503 Service Unavailable
    Date: Mon, 19 Dec 2011 15:42:30 GMT
    Retry-After: 1324339200
    Vary: Accept-Encoding
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: application/xml;charset=utf-8
    Cache-Control: private
    
    <?xml version="1.0" encoding="utf-8"?> <yahoo:error xmlns:yahoo="http://yahooapis.com/v1/base.rng" xml:lang="en-US"> <ya
    hoo:description>Rate Limit Exceeded</yahoo:description> <yahoo:detail>Key has exceeded its configured rate limit.</yahoo
    :detail> </yahoo:error>
    

    因此客户端无法继续。将其替换为工作版本,然后重试。看起来 URL 需要一些密钥,可能带有 cookie/header 或其他东西,我不熟悉那个特定的 web 服务。

    【讨论】:

    • 它似乎有某种配额(根据接受的请求),它可能超过了,所以它不会回答(直到下个月?)
    • 你能给我一个workign服务器链接..检查我的代码是否可以正常工作吗?
    • @DmitryMakovetskiyd:我不明白。
    【解决方案2】:

    Yahoo! Answers webservice 实际上不是 SOAP,而是基于 REST。

    例如,参见documentation for the question search method。对于您搜索“经济学”的示例,调用如下所示:

    http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=your-appid-here&amp;query=economics

    将返回 (sn-p):

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:answers" xsi:schemaLocation="urn:yahoo:answers http://answers.yahooapis.com/AnswersService/V1/QuestionResponse.xsd">
        <Question id="20080829001109AAOc4h9" type="Answered">
            <Subject>Economics...?? ?</Subject>
            <Content>HSC economics? i have a choice to do economics and i really have no idea what it's about, i am aware it is about money and finance however i am a bit vague with the subject, can any one shed some light on the subject??
    thanks for your help.
    </Content>
            <Date>2008-08-29 00:11:09</Date>
            <Timestamp>1219993869</Timestamp>
    
            <Link>http://answers.yahoo.com/question/?qid=20080829001109AAOc4h9</Link>
            <Category id="396545359">Higher Education (University +)</Category>
            <UserId>LJHkcrxcaa</UserId>
            <UserNick>Sam</UserNick>
            <UserPhotoURL></UserPhotoURL>
            <NumAnswers>2</NumAnswers>
    
            <NumComments>1</NumComments>
            <ChosenAnswer>Most people misunderstand what Economics is all about.  It is not particularly similar to accounting or finance.  Businessmen can benefit from understanding it, but it is not "business."  Rather, Economics is a Social Science concerned with understanding how humans allocate scare resources.  What goods and services do we produce?  How much of each good or service do we produce?  Who does the producing, and who does the consuming?  Do we ever choose not to produce (for example in order to conserve a natural resource because we value it for it's own sake)?  How do we decide these things?  Etc.  That is what Economics is about.  I personally find it a very interesting subject, though it takes some effort at first.</ChosenAnswer>
            <ChosenAnswererId>Gjj5eCG6aa</ChosenAnswererId>
            <ChosenAnswererNick>RCM</ChosenAnswererNick>
            <ChosenAnswerTimestamp>1220067546</ChosenAnswerTimestamp>
    
            <ChosenAnswerAwardTimestamp>1226969668</ChosenAnswerAwardTimestamp>
        </Question>
    ...
    </ResultSet>
    

    如果您想走这条路,您需要注册一个 AppID 密钥。这将有助于避免速率限制问题。

    另一个不错的选择(也更面向未来)是通过 YQL 访问 Answers API,示例查询如下:

    select * from answers.search where query="economics"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多