SDK
更新時間:
SDK
Java:Java SDK
Python:Python SDK
Go:Go SDK
服務接入點
地域名稱 | 地域ID | 公網接入地址 |
華北3(張家口) | cn-zhangjiakou | iqs.cn-zhangjiakou.aliyuncs.com |
示例代碼
Java SDK
前提條件
已安裝Java8及以上版本。
Maven依賴
通常建議使用最新版,以下內容僅為示例
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>iqs20240712</artifactId>
<version>2.0.3</version>
</dependency>
調用代碼
以“關鍵詞搜索”接口為例
package com.alibaba.e2.linkedmall.lmops.test.services;
import com.alibaba.e2.foundation.test.support.AssertUtils;
import com.aliyun.iqs20240712.Client;
import com.aliyun.iqs20240712.models.PlaceSearchNovaRequest;
import com.aliyun.iqs20240712.models.PlaceSearchNovaResponse;
import com.aliyun.iqs20240712.models.PlaceSearchNovaResponseBody;
import com.aliyun.iqs20240712.models.TransitIntegratedDirectionRequest;
import com.aliyun.iqs20240712.models.TransitIntegratedDirectionResponse;
import com.aliyun.iqs20240712.models.TransitIntegratedDirectionResponseBody;
import com.aliyun.tea.TeaException;
import org.junit.Test;
import java.util.List;
public class PopInterfaceTest {
public static final String ACCESS_KEY_ID = "ALIBABA_CLOUD_ACCESS_KEY_ID";
public static final String ACCESS_KEY_SECRET = "ALIBABA_CLOUD_ACCESS_KEY_SECRET";
static {
System.setProperty(ACCESS_KEY_ID, "***");
System.setProperty(ACCESS_KEY_SECRET, "***");
}
/**
* <b>description</b> :
* <p>使用AK&SK初始化賬號Client</p>
* @return Client
*
* @throws Exception
*/
public static Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(System.getProperty(ACCESS_KEY_ID))
.setAccessKeySecret(System.getProperty(ACCESS_KEY_SECRET));
config.endpoint = "iqs.cn-zhangjiakou.aliyuncs.com";
return new Client(config);
}
/**
*
* 關鍵詞搜索
*
* @throws Exception
*/
@Test
public void testDrivingDirectionNova() throws Exception {
Client client = createClient();
PlaceSearchNovaRequest request = new PlaceSearchNovaRequest();
request.setKeywords("餐廳");
request.setTypes("GAS_STATION|RESTAURANT|HOTEL|ATTRACTION");
try {
PlaceSearchNovaResponse response = client.placeSearchNova(request);
PlaceSearchNovaResponseBody body = response.getBody();
List<PlaceSearchNovaResponseBody.PlaceSearchNovaResponseBodyData> data = body.getData();
AssertUtils.assertNotNull(body.getData().get(0).getAddress(), "address is not null");
AssertUtils.assertNotNull(body.getData().get(0).getCityName(), "city name is not null");
} catch (TeaException error) {
// 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
// 錯誤 message
System.out.println(error.getMessage());
// 診斷地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
_error.printStackTrace();
TeaException error = new TeaException(_error.getMessage(), _error);
System.out.println(error.getMessage());
// 診斷地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Python SDK
前提條件
確保Python >= 3.7
安裝SDK
通常建議使用最新版,以下內容僅為示例
pip install alibabacloud_iqs20240712==2.0.3
調用代碼
以“關鍵詞搜索”接口為例
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_iqs20240712.client import Client as IQS20240712Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_iqs20240712 import models as iqs20240712_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> IQS20240712Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
# 工程代碼泄露可能會導致 AccessKey 泄露,并威脅賬號下所有資源的安全性。以下代碼示例僅供參考。
# 建議使用更安全的 STS 方式,更多鑒權訪問方式請參見:http://bestwisewords.com/document_detail/378659.html。
config = open_api_models.Config(
# 必填,請確保代碼運行環(huán)境設置了環(huán)境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id='***',
# 必填,請確保代碼運行環(huán)境設置了環(huán)境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret='***'
)
# Endpoint 請參考 https://api.aliyun.com/product/IQS
config.endpoint = 'iqs.cn-zhangjiakou.aliyuncs.com'
return IQS20240712Client(config)
@staticmethod
def main(args: List[str]) -> None:
client = Sample.create_client()
request = iqs20240712_models.PlaceSearchNovaRequest(
keywords="餐廳",
types="GAS_STATION|RESTAURANT|HOTEL|ATTRACTION"
)
runtime = util_models.RuntimeOptions()
headers = {}
try:
# 復制代碼運行請自行打印 API 的返回值
response = client.place_search_nova_with_options(request, headers, runtime)
print(response)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
request = iqs20240712_models.PlaceSearchNovaRequest(
keywords="餐廳",
types="GAS_STATION|RESTAURANT|HOTEL|ATTRACTION"
)
runtime = util_models.RuntimeOptions()
headers = {}
try:
# 復制代碼運行請自行打印 API 的返回值
response = await client.place_search_nova_with_options_async(request, headers, runtime)
print(response)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
# Go 環(huán)境版本必須不低于 1.10.x
Go SDK
前提條件
Go環(huán)境版本必須不低于 1.10.x
安裝SDK
go get github.com/alibabacloud-go/iqs-20240712
調用代碼
以“關鍵詞搜索”接口為例
package awesomeProject
// This file is auto-generated, don't edit it. Thanks.
import (
"encoding/json"
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
iqs20240712 "github.com/alibabacloud-go/iqs-20240712/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"os"
"strings"
)
// Description:
//
// 使用AK&SK初始化賬號Client
//
// @return Client
//
// @throws Exception
func CreateClient() (_result *iqs20240712.Client, _err error) {
// 工程代碼泄露可能會導致 AccessKey 泄露,并威脅賬號下所有資源的安全性。以下代碼示例僅供參考。
// 建議使用更安全的 STS 方式,更多鑒權訪問方式請參見:http://bestwisewords.com/document_detail/378661.html。
config := &openapi.Config{
// 必填,請確保代碼運行環(huán)境設置了環(huán)境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。
AccessKeyId: tea.String("***"),
// 必填,請確保代碼運行環(huán)境設置了環(huán)境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
AccessKeySecret: tea.String("***"),
}
// Endpoint 請參考 https://api.aliyun.com/product/IQS
config.Endpoint = tea.String("iqs.cn-zhangjiakou.aliyuncs.com")
_result = &iqs20240712.Client{}
_result, _err = iqs20240712.NewClient(config)
return _result, _err
}
func _main(args []*string) (_err error) {
client, _err := CreateClient()
if _err != nil {
return _err
}
request := &iqs20240712.PlaceSearchRequest{
keywords: "餐廳",
types: "GAS_STATION|RESTAURANT|HOTEL|ATTRACTION",
}
runtime := &util.RuntimeOptions{}
headers := make(map[string]*string)
tryErr := func() (_e error) {
defer func() {
if r := tea.Recover(recover()); r != nil {
_e = r
}
}()
// 復制代碼運行請自行打印 API 的返回值
_, _err = client.PlaceSearchWithOptions(request, headers, runtime)
if _err != nil {
return _err
}
return nil
}()
if tryErr != nil {
var error = &tea.SDKError{}
if _t, ok := tryErr.(*tea.SDKError); ok {
error = _t
} else {
error.Message = tea.String(tryErr.Error())
}
// 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
// 錯誤 message
fmt.Println(tea.StringValue(error.Message))
// 診斷地址
var data interface{}
d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
d.Decode(&data)
if m, ok := data.(map[string]interface{}); ok {
recommend, _ := m["Recommend"]
fmt.Println(recommend)
}
_, _err = util.AssertAsString(error.Message)
if _err != nil {
return _err
}
}
return _err
}
func main() {
err := _main(tea.StringSlice(os.Args[1:]))
if err != nil {
panic(err)
}
}
文檔內容是否對您有幫助?