Step 2: Passing the code to get the access_token

After the user is redirected back to your site, you can take the passed ‘code’ and call the access_token API as follows:

https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code

Important Note:

  • If you have an International Official Account, use api.wechat.com.
  • If you have a China Official Account, use api.weixin.qq.com.

Parameters

Response field

Example:

{   
    "access_token":"ACCESS_TOKEN",
    "expires_in":7200,
    "refresh_token":"REFRESH_TOKEN",
    "openid":"OPENID",
    "scope":"SCOPE",
    "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL" 
}

Parameters

An error message will look something like this:

{
    "errcode":40029,
    "errmsg":"invalid code"
}

For more info regarding the error messages, refer here.

Go to step 3

results matching ""

    No results matching ""