2011-12-19 54 views
0

我使用這個網站爲指導,以我的web服務..未能使用Web服務與PHP

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); 

顯然,我無法檢索什麼..並得到這個錯誤:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://answers.yahooapis.com/AnswersService/V1/questionSearch' : failed to load external entity "http://answers.yahooapis.com/AnswersService/V1/questionSearch" in C:\xampp\htdocs\Unnamed Site 2\untitled1.php:11 Stack trace: #0 C:\xampp\htdocs\Unnamed Site 2\untitled1.php(11): SoapClient->SoapClient('http://answers....') #1 {main} thrown in C:\xampp\htdocs\Unnamed Site 2\untitled1.php on line 11

回答

1

爲WebService與您的代碼工作,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服務。

+0

它看起來像有某種配額(在接受請求),它可能超過,所以它不會回答(直到下個月?) – Alfabravo 2011-12-19 15:47:10

+0

你可以給我一個工作服務器鏈接..檢查我的代碼是否適用於它? – 2011-12-19 15:52:19

+0

@DmitryMakovetskiyd:我不明白。 – hakre 2011-12-19 15:58:32

0

Yahoo! Answers webservice實際上並不是SOAP,但是是基於REST的。

例如,參見documentation for the question search method。爲您的樣品搜索「經濟學」,調用看起來像:

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

將返回(片段):

<?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訪問答案API,與樣本查詢類似如下:

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