雅虎商店订单 API 访问 [英] Yahoo Store Order API Access
问题描述
我花了很长时间试图弄清楚这个雅虎商店 API 的东西.我已经在互联网上搜索了示例,但几乎一无所获.我已经创建了我的请求:
I'm having a heck of a time trying to figure out this Yahoo Store API stuff. I've scoured the internet for examples but have come up with next to nothing. I've created my request:
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(存储在String地址中)
and have attempted to send the data to the URL listed in the API doc: https://MyStoreID.order.store.yahooapis.com/V1/order (stored in String address)
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?在这一点上的任何帮助表示赞赏.谢谢.
I'm pretty much completely lost with this as yahoo provides some poor documentation and no examples that I could find. Has anyone ever tried to connect to a Yahoo Store using Yahoo API calls from Java? Any help at this point is appreciated. Thanks.
推荐答案
我能够解决这个问题.所以我会为其他人发布解决方案.这是一个 PHP 脚本,它将请求有关订单号 5863 的所有信息.我可以从 Java 程序调用 PHP 脚本并根据需要从那里解析结果.
I was able to figure this out. So I will post the solution for everyone else. This is a PHP script that will request all information about order number 5863. I can call the PHP script from a java program and parse the result as needed from there.
<?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);
?>
这篇关于雅虎商店订单 API 访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!