Use the Alibaba Cloud Python SDK to call API operations. This example uses the GetPhoneNumberIdentificationUrl operation to obtain the verification URL for your phone number.
View the API documentation
Before you call an API operation, read the documentation about the GetPhoneNumberIdentificationUrl operation to understand the required parameters and permissions. For more information, see API overview.
Authentication
Step 1: Create a RAM user and grant permissions
Your root account has full permissions. Use a RAM user for API calls and routine O&M. For more information, see Overview.
-
Create a RAM user: Go to the Create User page. Specify the required information, select Permanent AccessKey for Access Configuration, then click OK. Save your AccessKey for later use.
-
Grant permissions to the RAM User: Go to the Users page. Find the RAM user that you created and click Attach Policy in the Actions column. In the Policy search box, enter AliyunDysmsFullAccess, select the policy, and then click OK.
-
AliyunDytnsReadOnlyAccess: Grants read-only permissions on Cell Phone Number Service.
-
AliyunDytnsFullAccess: Grants full management permissions on Cell Phone Number Service.
-
To create a custom policy, see RAM authorization.
Step 2: Obtain access credentials
Configure your AccessKey pair using environment variables. For information about how to configure environment variables, see Configure environment variables on Linux, macOS, and Windows.
To prevent security risks, avoid hard-coding your AccessKey pair. Instead, retrieve it from environment variables.
Call the API operation
This example uses the Python SDK. You can call API operations in a similar way with SDKs for other programming languages. For more information, see Cell Phone Number Service SDK. For other methods to call operations, see Call methods.
Prepare Python environment
Download and install Python 3. If Python is already installed, run the python --version command to check its version.
Before calling the API, configure environment variables for your access credentials: VMS_AK_ENV (AccessKey ID) and VMS_SK_ENV (AccessKey Secret). For configuration methods, see Configure environment variables in Linux, macOS, and Windows.
Install dependencies
Run the following commands to install the dependencies:
pip3 install alibabacloud_credentials
pip install alibabacloud_dytnsapi20230101
pip3 install alibabacloud_tea_console
Download the sample code
-
On the Parameters tab, set the required parameters. In this example, Region is set to China (Hangzhou).
-
On the SDK Sample Code tab, select Python and click Download Project.
-
Decompress the package and go to the alibabacloud_sample directory.
Run the code
Run the following command:
python sample.py
The following sample result is returned:
{
"headers":{
"access-control-allow-origin":"*",
"date":"Wed, 24 Apr 2024 09:27:47 GMT",
"content-length":"128",
"keep-alive":"timeout=25",
"x-acs-request-id":"7250E964-DFF7-5343-9CB6-4BA94AAD320F",
"connection":"keep-alive",
"content-type":"application/json;charset=utf-8",
"etag":"1Yd7WQjEOnVh24d2GHVjkIQ8",
"access-control-expose-headers":"*",
"x-acs-trace-id":"d553c17e7b941c8f9086ebe9cea4b5db"
},
"statusCode":200,
"body":{
"code":"OK",
"data":{
"carrierCode":"CTCC",
"verifyResult":1
},
"message":"OK",
"requestId":"7250E964-DFF7-5343-9CB6-4BA94AAD320F"
}
}