Skip to content

Python SDK 빠른 시작

이 문서는 Python SDK를 사용하여 일반적인 작업을 수행하는 빠른 시작 가이드를 제공합니다. SDK를 설치하는 방법, 액세스 자격 증명을 구성하는 방법, 최신 업그레이드 정보를 검색하는 등의 기본 작업을 학습하게 됩니다.

참고 사항

  • Python SDK를 사용하여 요청을 보내려면 Client 인스턴스를 초기화해야 합니다. 이 문서에서는 기본 구성을 로드하여 Client를 생성합니다. 클라이언트에 대한 자세한 구성 옵션은 클라이언트 구성을 참조하세요.

전제 조건

  • UpgradeLink 계정을 등록했습니다.
  • AccessKey 및 AccessSecret을 얻었습니다.
  • URL 애플리케이션 업그레이드 전략을 구성했습니다.

자격 증명 얻기

img.jpg

Python SDK 설치

  • 먼저 Python 컴파일 및 실행 환경을 설치하세요. 다음 명령어를 사용하여 Python이 성공적으로 설치되었는지 확인하세요:
shell
  python --version

현재 적절한 Python 컴파일 및 실행 환경이 없는 경우, Python 설치를 참조하여 다운로드 및 설치하세요.

  • 다음 명령어를 실행하여 Python SDK 코드 패키지를 설치합니다.
shell
pip install upgradelink-api-python
  • 다음 코드를 사용하여 Python SDK 코드 패키지를 가져옵니다.
python
import upgradelink_api_python

빠른 사용

다음 샘플 프로그램은 Client를 초기화하고 URL 애플리케이션의 최신 업그레이드 정보를 검색하는 방법을 보여줍니다.

URL 애플리케이션 최신 업그레이드 정보 가져오기

python

from upgradelink_api_python import models as upgrade_link_models
from upgradelink_api_python.client import Client

def main():
    # 구성 객체 생성
    config = upgrade_link_models.Config(
        access_key="mui2W50H1j-OC4xD6PgQag",  # 예제 키, 실제 키로 바꾸세요
        access_secret="PEbdHFGC0uO_Pch7XWBQTMsFRxKPQAM2565eP8LJ3gc",  # 예제 키, 실제 키로 바꾸세요
        protocol="HTTPS",
        endpoint="api.upgrade.toolsetlink.com"
    )
    
    # 클라이언트 생성
    client = Client(config)
    
    # 요청 매개변수 설정
    url_key = "uJ47NPeT7qjLa1gL3sVHqw"  # URL 애플리케이션의 고유 식별자
    version_code = 1  # 현재 애플리케이션 버전 번호
    appoint_version_code = 0  # 지정된 버전 번호, 0은 최신 버전을 의미합니다
    dev_model_key = ""  # 장치 모델 식별자, 선택 사항
    dev_key = ""  # 장치 식별자, 선택 사항
    
    # 요청 객체 구축
    request = upgrade_link_models.UrlUpgradeRequest(
        url_key=url_key,
        version_code=version_code,
        appoint_version_code=appoint_version_code,
        dev_model_key=dev_model_key,
        dev_key=dev_key
    )
    
    try:
        # API 인터페이스 호출
        response = client.url_upgrade(request)
        
        # 응답 결과 처리
        if response.code == 200:
            print("Request successful!")
            print(f"Message: {response.msg}")
            print(f"Trace ID: {response.trace_id}")
            
            # 업그레이드 데이터 처리
            if response.data:
                data = response.data
                print("\nUpgrade Information:")
                print(f"URL Key: {data.url_key}")
                print(f"Version Name: {data.version_name}")
                print(f"Version Code: {data.version_code}")
                print(f"URL Path: {data.url_path}")
                print(f"Upgrade Type: {data.upgrade_type}")  # 1: 강제 업그레이드, 2: 권장 업그레이드, 3: 선택적 업그레이드
                print(f"Upgrade Prompt Content: {data.prompt_upgrade_content}")
                
                # 다른 업그레이드 유형 처리
                if data.upgrade_type == 1:
                    print("\nThis is a forced upgrade. Please upgrade the application immediately.")
                    # 강제 업그레이드 로직 실행
                elif data.upgrade_type == 2:
                    print("\nThis is a recommended upgrade. It is recommended that users upgrade the application.")
                    # 권장 업그레이드 로직 실행
                elif data.upgrade_type == 3:
                    print("\nThis is an optional upgrade. Users can choose whether to upgrade.")
                    # 선택적 업그레이드 로직 실행
        else:
            print(f"Request failed, error code: {response.code}")
            print(f"Error message: {response.msg}")
            print(f"Trace ID: {response.trace_id}")
            
    except Exception as e:
        print(f"Error occurred when calling API: {e}")

if __name__ == "__main__":
    main()

toolsetlink@163.com