1. 参数
1.1. 入参
参数 | 类型 | 是否必传 | 说明 |
serviceId | Long | 是 | 服务id |
partition | List | 否,odps类型可传 | 分区信息,odps类型可传,示例: [ { "ds": "20230101", "hh": "23" } ] |
url | String | 否 | url必须为可wget下载的txt文档地址,文档内容每行为一条记录,每条记录为json格式,主键重复会触发更新。注意:我们不会对json内容进行校验,调用前请确保txt内容的正确性 |
{
"serviceId": 1,
"partition": [
{
"ds": "20230101",
"hh": "23"
}
],
"url": "http://xxxx.txt"
}
1.2. 出参
参数名称 | 参数类型 | 参数描述 | ||
code | Integer | 错误码 | ||
success | Boolean | 是否成功 | ||
requestId | String | 请求id | ||
data | Long | 导入id | ||
msg | String | 响应信息 |
{
"code":200,
"data":1,
"msg": null,
"requestId":"326F95A0-720A-5293-BDA7-4B91B09E636B",
"success":true
}
2. SDK调用
2.1. Java SDK
2.1.1. Maven依赖
相关Java SDK引入的Maven依赖
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alinlp20200629</artifactId>
<version>2.2.1</version>
</dependency>
2.1.2. 调用示例
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// 必填,您的 AccessKey ID
.setAccessKeyId(accessKeyId)
// 必填,您的 AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// Endpoint 请参考 https://api.aliyun.com/product/alinlp
config.endpoint = "alinlp.cn-beijing.aliyuncs.com";
return new Client(config);
}
public static void main(String[] args_) throws Exception {
ImportServiceData();
}
public static void ImportServiceData() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
Client client = createClient(AccessConstant.AK3, AccessConstant.SK3);
ImportServiceDataRequest request = new ImportServiceDataRequest()
.setServiceId(1L);
try {
ImportServiceDataResponse response = client.importServiceData(request);
System.out.println(JSON.toJSONString(response.getBody(), SerializerFeature.PrettyFormat));
} catch (Exception e) {
e.printStackTrace();
}
}
2.2. Python SDK
2.2.1. pip源
pip install aliyun-python-sdk-alinlp==1.0.24
pip install aliyun-python-sdk-core
2.2.2. 调用示例
from aliyunsdkalinlp.request.v20200629 import ImportServiceDataRequest
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.auth.credentials import AccessKeyCredential
import os
os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'] = 'xxxx'
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'] = 'xxxx'
def data_import():
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)
request = ImportServiceDataRequest.ImportServiceDataRequest()
request.set_ServiceId(214)
request.set_Partition([{"ds": "20230101", "hh": "23"}])
request.set_accept_format('json')
response = client.do_action_with_exception(request)
# python2: print(response)
print(str(response, encoding='utf-8'))
if __name__ == '__main__':
data_import()
文档内容是否对您有帮助?