获取SDK代码示例
接口说明
该接口查询的是公开信息,不涉及账号特殊归属等信息,故不支持授权。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
调试
授权信息
请求语法
POST /api/product/makeCode HTTP/1.1
请求参数
|
名称 |
类型 |
必填 |
描述 |
示例值 |
| body |
object |
否 |
生成代码示例请求体 |
|
| callType |
string |
否 |
SDK 调用类型,typed 为产品专属 SDK 模式,generic 为 Common 泛化调用模式,默认为 typed。 |
typed |
| product |
string |
是 |
云产品 Code。 |
Ecs |
| apiVersion |
string |
否 |
OpenAPI 版本。 |
2014-05-26 |
| apiName |
string |
是 |
OpenAPI 名称。 |
DescribeInstances |
| regionId |
string |
否 |
地域 ID。 |
cn-hangzhou |
| language |
string |
是 |
代码示例编程语言。 |
java |
| params |
string |
否 |
OpenAPI 业务请求参数 JSON 字符串,键为参数名,值为序列化后的参数值。 |
{"RegionId":"cn-hangzhou"} |
返回参数
|
名称 |
类型 |
描述 |
示例值 |
|
object |
|||
| code |
integer |
业务状态码,0 表示成功,1 表示 workbench 业务异常。 |
0 |
| message |
string |
业务错误信息,仅当 code 不为 0 时返回。 |
SDK 示例生成出错,请联系支持群开发同学解决 |
| data |
object |
生成的多语言 SDK 代码示例及依赖信息。 |
{} |
| demoSdk |
string |
对应的代码示例内容 |
package com.aliyun.sample;\n\nimport com.aliyun.tea.*;\n\npublic class Sample {\n\n /**\n * description :\n * 使用凭据初始化账号Client \n * @return Client\n * \n * @throws Exception\n */\n public static com.aliyun.teaopenapi.Client createClient() throws Exception {\n // 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378657.html。\n com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();\n com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()\n .setCredential(credential);\n // Endpoint 请参考 https://api.aliyun.com/product/Ecs\n config.endpoint = \"ecs.us-west-1.aliyuncs.com\";\n return new com.aliyun.teaopenapi.Client(config);\n }\n\n /**\n * description :\n *API 相关 \n * \n * @param path string Path parameters\n * @return OpenApi.Params\n */\n public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {\n com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()\n // 接口名称\n .setAction(\"DescribeInstances\")\n // 接口版本\n .setVersion(\"2014-05-26\")\n // 接口协议\n .setProtocol(\"HTTPS\")\n // 接口 HTTP 方法\n .setMethod(\"POST\")\n .setAuthType(\"AK\")\n .setStyle(\"RPC\")\n // 接口 PATH\n .setPathname(\"/\")\n // 接口请求体内容格式\n .setReqBodyType(\"json\")\n // 接口响应体内容格式\n .setBodyType(\"json\");\n return params;\n }\n\n public static void main(String[] args_) throws Exception {\n \n com.aliyun.teaopenapi.Client client = Sample.createClient();\n com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo();\n // query params\n java.util.Map |
| cost |
integer |
生成耗时,单位毫秒。 |
100 |
| sdkDependency |
object |
当前输入的云产品 API 版本,编程语言以及调用方式对应的 SDK 安装信息(与 GetSdkDependencies 单条结果同结构)。 |
{"packageName":"com.aliyun/openapiexplorer20241130","sdkVersion":"1.3.0","platform":"maven","install":" |
| packageName |
string |
SDK 包名称。 |
com.aliyun/openapiexplorer20241130 |
| sdkVersion |
string |
SDK 包版本。 |
1.3.0 |
| platform |
string |
SDK 包管理平台,如 github/maven/pypi/nuget/npm。 |
maven |
| install |
string |
SDK 安装命令。Java 为 Maven |
|
示例
正常返回示例
JSON格式
{
"code": 0,
"message": "SDK 示例生成出错,请联系支持群开发同学解决",
"data": {
"demoSdk": "package com.aliyun.sample;\\n\\nimport com.aliyun.tea.*;\\n\\npublic class Sample {\\n\\n /**\\n * description :\\n *
使用凭据初始化账号Client\\n * @return Client\\n * \\n * @throws Exception\\n */\\n public static com.aliyun.teaopenapi.Client createClient() throws Exception {\\n // 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378657.html。\\n com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();\\n com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()\\n .setCredential(credential);\\n // Endpoint 请参考 https://api.aliyun.com/product/Ecs\\n config.endpoint = \\\"ecs.us-west-1.aliyuncs.com\\\";\\n return new com.aliyun.teaopenapi.Client(config);\\n }\\n\\n /**\\n * description :\\n *
API 相关\\n * \\n * @param path string Path parameters\\n * @return OpenApi.Params\\n */\\n public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {\\n com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()\\n // 接口名称\\n .setAction(\\\"DescribeInstances\\\")\\n // 接口版本\\n .setVersion(\\\"2014-05-26\\\")\\n // 接口协议\\n .setProtocol(\\\"HTTPS\\\")\\n // 接口 HTTP 方法\\n .setMethod(\\\"POST\\\")\\n .setAuthType(\\\"AK\\\")\\n .setStyle(\\\"RPC\\\")\\n // 接口 PATH\\n .setPathname(\\\"/\\\")\\n // 接口请求体内容格式\\n .setReqBodyType(\\\"json\\\")\\n // 接口响应体内容格式\\n .setBodyType(\\\"json\\\");\\n return params;\\n }\\n\\n public static void main(String[] args_) throws Exception {\\n \\n com.aliyun.teaopenapi.Client client = Sample.createClient();\\n com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo();\\n // query params\\n java.util.Map queries = new java.util.HashMap<>();\\n queries.put(\\\"RegionId\\\", \\\"us-west-1\\\");\\n // runtime options\\n com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();\\n com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()\\n .setQuery(com.aliyun.openapiutil.Client.query(queries));\\n // 返回值实际为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。\\n Object resp = client.callApi(params, request, runtime);\\n System.out.println(new com.google.gson.Gson().toJson(resp));\\n }\\n}\\n",
"cost": 100,
"sdkDependency": {
"packageName": "com.aliyun/openapiexplorer20241130",
"sdkVersion": "1.3.0",
"platform": "maven",
"install": "\\n com.aliyun\\n openapiexplorer20241130\\n 1.3.0\\n"
}
}
}
错误码
|
HTTP status code |
错误码 |
错误信息 |
描述 |
|---|---|---|---|
| 400 | InvalidParam.Body | Request body is required. | |
| 400 | InvalidParam.Product | Product name is required and cannot be null or empty. | |
| 400 | InvalidParam.ApiVersion | API version is required and cannot be null or empty. | |
| 400 | InvalidParam.ApiName | API name is required and cannot be null or empty. | |
| 400 | InvalidParam.Format | Product/apiVersion/apiName format is invalid. | |
| 400 | InvalidParam.Language | Language format is invalid. | |
| 400 | InvalidParam.CallType | CallType must be typed or generic. | |
| 502 | WorkbenchProxy.RequestFailed | Failed to generate code sample. |
访问错误中心查看更多错误码。
变更历史
更多信息,参考变更详情。