Obtaining API Call Credentials

View llm.txt

Last edited on 2026-07-04

This API should be called on the server side and cannot be called directly on the client side (Mini Program, web page, APP, etc.). For details, please refer to API Call Guide.

API English Name: getAccessToken

This interface is used to obtain a globally unique background API call credential (Access Token). The token is valid for 7,200 seconds. Developers should keep it securely. For usage guidelines, please refer to this document.

It is recommended to use obtaining a stable version of API call credentials.

1. Call Method

HTTPS Call

GET https://api.weixin.qq.com/cgi-bin/token

Cloud Call

  • This API does not support cloud call.

Third-party Call

  • This API does not support third-party platform calls.

2. Request Parameters

Query Parameters Query String Parameters

None

Request Body Request Payload

ParameterTypeRequiredDescription
grant_typestringYesEnter client_credential
appidstringYesThe unique credential for the account, namely AppID. Click here to view how to obtain AppID.
secretstringYesThe unique credential key, namely AppSecret. Click here to view how to obtain AppSecret.

3. Response Parameters

Response Body Response Payload

ParameterTypeDescription
access_tokenstringThe obtained credentials
expires_innumberCredential validity period, in seconds. Currently, it must be within 7,200 seconds.

4. Notes

  1. The Access Tokens for different application types are isolated from each other and can only be used to call interfaces specific to their respective application types.
  2. AppSecret is the key used by the account to access background API interfaces. Developers should keep it securely to prevent account misuse due to leakage.
  3. If there is no need to use AppSecret for an extended period, developers can freeze it to enhance account security.
  4. Once AppSecret is frozen, developers cannot use it to obtain Access Token (the interface will return error code 40243). This does not affect the normal use of basic account functions, third-party authorized background interface calls, or cloud development background interface calls.
  5. Developers can unfreeze AppSecret at any time.

For information on how to obtain AppID and AppSecret, as well as how to freeze/unfreeze AppSecret, please refer to this document.

5. Code Example

Request Example

GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

Response Example

{
  "access_token": "ACCESS_TOKEN",
  "expires_in": 7200
}

6. Error Codes

The following is the error code list of this API, other error codes can refer to Common Error Codes; When encountering errors in calling the API, you can use the official API Diagnostic Tool to assist in locating and analyzing problems.

Error CodeError DescriptionSolution
-1system errorThe system is busy. Please try again later.
40001invalid credential  access_token isinvalid or not latestAn error occurred with AppSecret when obtaining access_token, or the access_token is invalid. Please verify the correctness of AppSecret or ensure that you are calling the interface for the correct public account.
40002invalid grant_typeThe credential type is invalid.
40013invalid appidThe AppID is invalid. Please check its correctness, avoiding special characters and paying attention to case sensitivity.
40125The secret is invalid.Please verify the correctness of the secret, avoiding special characters and paying attention to case sensitivity.
40164The IP address used to call the interface is not in the allowlist.Please add the IP address to the interface allowlist.
40243AppSecret has been frozen. Please unfreeze it before making another call.Click here to view how to unfreeze AppSecret.
41004appsecret missingThe secret parameter is missing.
50004Using the token interface is prohibited.
50007The account has been frozen.

7. Applicable Scope

API callable status for different account types:
Mini ProgramOfficial AccountService AccountMini GameWeChat ShopAlliance AgencyInfluencerShop SupplierMobile AppWebsite AppChannels WindowMulti-platform App
✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
  • ✔:This account type can call this API。
  • Other account types not explicitly declared cannot call this API unless otherwise specified.