# Get Interface Call Credentials
Interface should be called on the server side, not in the front end (Weixin Mini Program, web pages, APP, etc.) directly called, specific reference interface call guide
Interface name: getAccessToken
- Get the global unique background interface call credentials, token valid for 7200s, developers need to be properly saved.
- If you use the cloud to develop , you can call](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html) through the [cloud without maintaining access_token calls.
- If you use to host in the cloud, you can also use WeChat token / open interface to service without maintenance.
# 1. How to call
# HTTPS calls
GET https://api.weixin.qq.com/cgi-bin/token
# Cloud Calls
- This interface does not support cloud calls
# Third party invocation
- Third Party Platform calls are not supported by this interface.
# 2. Request parameters
# Query parametersQuery String parameters
nothing
# Request BodyRequest Payload
Parameter Name | type | Required to fill in | Introductions |
---|---|---|---|
grant_type | string | yes | Fill in client_credential |
appid | string | yes | The account's unique credentials, that is, AppID, click here to see How to get Appid |
secret | string | yes | Unique credential key, AppSecret, click here to see How to get AppSecret |
# 3. Return Parameters
# Response Payload
Parameter Name | type | Introductions |
---|---|---|
access_token | string | Credentials obtained |
expires_in | number | Credential validity time, in units: seconds. The current value is within 7,200 seconds. |
# 4. Note
# AppSecret Security Alert
- AppSecret is the key for the account to use the background API interface, please keep it properly, to avoid the risk of the account being used by others due to leakage. If there is no use of AppSecret for a long time, developers can use the AppSeceret to freeze and improve the security of the account. After the AppSecret freeze, developers cannot use AppSecret to obtain Access tokens (interface returns error code 40243), which does not affect the normal use of the basic functions of the account, does not impact the call of the backend interface through third party authorization, and does not influence cloud development to call the backend Interface. Developers can unfreeze AppSecret at any time.
- Click here to view How to freeze / defreeze AppSecret
# 5. Code examples
Example Requests
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Return an example
{
"access_token": "ACCESS_TOKEN",
"expires_in": 7200
}
# 6. Error code
The following is a list of error codes for this interface, other error codes can refer to General error codes
Error code | Error Description | Solutions |
---|---|---|
-1 | system error | The system is busy, so the developer is asked to try again in a few minutes. |
40001 | invalid credential access_token isinvalid or not latest | AppSecret error while getting access_token, or access_token is invalid.Developers should check that AppSecret is correct, or that they are calling interfaces for the appropriate Official Account |
40002 | invalid grant_type | Types of Unlawful Credentials |
40013 | invalid appid | Invalid AppID, please check the correctness of the AppID, avoid abnormal characters, pay attention to the case |
40125 | An illegal secret | Please check the correctness of the secret, avoid abnormal characters, pay attention to the case |
40164 | The IP address of the calling interface is not in the whitelist | Please set it in the interface IP whitelist |
40243 | AppSecret has been frozen, please unfreeze and call again. | Click here to see How to unfreeze AppSecret |
41004 | appsecret missing | Missing secret parameter |
50004 | Disable token interface | |
50007 | The account has been frozen. |
# 7. Scope of application
How this interface can be invoked under different account types:
Weixin Mini Program | Official Account | Service Account | MiniGame | Weixin Store | Alliance Shipping Agency | Delivery Assistant | Mobile App | Website App | Weixin Channels Assistant | Multi-platform App |
---|---|---|---|---|---|---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
- ✔: The account can call this interface
- Other account types that are not expressly stated may not be called on this interface without special instructions;