2

我有一段时间试图弄清楚这个 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 文档中列出的 URL: 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?在这一点上的任何帮助表示赞赏。谢谢。

4

1 回答 1

2

我能够弄清楚这一点。所以我会为其他人发布解决方案。这是一个 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);
?>
于 2013-04-11T19:51:53.503 回答