Yahoo Store订单API访问

时间:2013-04-01 22:26:26

标签: java yahoo yahoo-api

我正试图找出这个Yahoo Store API的东西。我已经在互联网上搜索了一些例子,但几乎没有提出任何问题。我创建了我的请求:

String data = "";
data += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
data += "<ystorewsRequest>";
data += "<StoreID>" + storeID + "</StoreID>";
data += "<SecurityHeader>";
data += "<PartnerStoreContractToken>" + token + "</PartnerStoreContractToken>";
data += "</SecurityHeader>";
data += "<Version> 1.0 </Version>";
data += "<Verb> get </Verb>";
data += "<ResourceList>";
data += "<OrderListQuery>";
data += "<Filter>";
data += "<Include> all </Include>";
data += "</Filter>";
data += "<QueryParams>";
data += "<OrderID> 5441 </OrderID>";
data += "</QueryParams>";
data += "</OrderListQuery>";
data += "</ResourceList>";
data += "</ystorewsRequest>";

并尝试将数据发送到API文档中列出的网址: https://MyStoreID.order.store.yahooapis.com/V1/order(存储在字符串地址中)

url = new URL(address);

HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
conn.setRequestMethod("POST");

String urlParameters = "query=" + data;

DataOutputStream wr = new DataOutputStream (
          conn.getOutputStream ());
  wr.writeBytes (urlParameters);
  wr.flush ();
  wr.close ();

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));


line = rd.readLine();
rd.close();

结果我收到了这个错误;

java.io.IOException: Server returned HTTP response code: 400 for URL: https://MyStoreID.order.store.yahooapis.com/V1/order
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
由于雅虎提供了一些糟糕的文档而没有我能找到的例子,所以我完全迷失了。有没有人试图使用Java的Yahoo API调用连接到Yahoo Store?在这一点上的任何帮助表示赞赏。感谢。

1 个答案:

答案 0 :(得分:1)

我能够弄清楚这一点。所以我会为其他人发布解决方案。这是一个PHP脚本,它将请求有关订单号5863的所有信息。我可以从java程序调用PHP脚本并根据需要从那里解析结果。

<?php

//build xml request
$data = "<?xml version='1.0' encoding='utf-8'?>";
$data .= "<ystorewsRequest>";
$data .= "<StoreID>your store id</StoreID>";     //insert your store id
$data .= "<SecurityHeader>";
$data .= "<PartnerStoreContractToken>your token</PartnerStoreContractToken>";  //insert your token`
$data .= "</SecurityHeader>";
$data .= "<Version>1.0</Version>";
$data .= "<Verb>get</Verb>";
$data .= "<ResourceList>";
$data .= "<OrderListQuery>";
$data .= "<Filter>";
$data .= "<Include>all</Include>";
$data .= "</Filter>";
$data .= "<QueryParams>";
$data .= "<OrderID>5863</OrderID>";
$data .= "</QueryParams>";
$data .= "</OrderListQuery>";
$data .= "</ResourceList>";
$data .= "</ystorewsRequest>"; 

//send request to yahoo order api
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);    
curl_setopt($ch, CURLOPT_URL, "https://your_store_id.order.store.yahooapis.com/V1/order");          //insert your store id
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$content=curl_exec($ch);

//print raw xml data returned from yahoo
echo htmlentities( $content);
?>