基于 XML API 调用创建 Guzzle 服务定义
Posted
技术标签:
【中文标题】基于 XML API 调用创建 Guzzle 服务定义【英文标题】:Create Guzzle Service Definition Based on XML API call 【发布时间】:2013-02-04 16:04:47 【问题描述】:我是 Guzzle 的新手,我正在尝试利用它的服务定义。我能够像这样对 eBay API 进行基本调用。
$request = $client->post('', [
'X-EBAY-API-COMPATIBILITY-LEVEL' => '807',
'X-EBAY-API-DEV-NAME' => 'my-dev-name',
'X-EBAY-API-APP-NAME' => 'my-app-name',
'X-EBAY-API-CERT-NAME' => 'my-cert-name',
'X-EBAY-API-SITEID' => '0',
'X-EBAY-API-CALL-NAME' => 'GeteBayOfficialTime',
],
'<?xml version="1.0" encoding="utf-8"?>
<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>AgAAAA**AQAAAA**</eBayAuthToken>
</RequesterCredentials>
</GeteBayOfficialTimeRequest>'
);
下一步是将其转换为服务定义。通过阅读文档、论坛等,我想出了这个。
"name": "eBay example",
"apiVersion": "2012-10-14",
"baseUrl": "https://api.sandbox.ebay.com/ws/api.dll",
"description": "it's the eBay API",
"operations":
"GeteBayOfficialTime":
"httpMethod": "POST",
"uri": "",
"responseClass": "GeteBayOfficialTime",
"summary": "Gets the official time according to eBay",
"data":
"xmlRoot":
"name": "GeteBayOfficialTime"
,
"parameters":
"RequesterCredentials":
"location": "xml",
"type": "string"
,
"models":
"GeteBayOfficialTime":
"type": "array",
"items":
"type": "object",
"properties":
"TiemStamp":
"location": "xml",
"type": "string"
但这是不正确的。我希望更开明的人可以帮助完成此示例以供参考。谢谢!
【问题讨论】:
迈克,你设法让它工作了吗?我也有类似的情况。 【参考方案1】:参数应该是这样的:
"parameters":
"RequesterCredentials":
"location": "xml",
"type": "array",
"items:
"name" = "eBayAuthToken",
"type" = "string"
这将是你的命令
$command = $client->getCommand("GeteBayOfficialTime", array("RequesterCredentials" => array("AgAAAA**AQAAAA**")));
【讨论】:
以上是关于基于 XML API 调用创建 Guzzle 服务定义的主要内容,如果未能解决你的问题,请参考以下文章
使用 Lumen + Guzzle 的 API 调用提供错误数组到字符串的转换
如何在不使用 curl 和 guzzle 的情况下从控制器 Laravel 调用 API,因为它不起作用 [关闭]