An invalid access_token prompt appears when the user obtains the basic information after the Public Account web page authorization.

Source: Internet
Author: User
Tags openid
First, I confirm that my public account is the Authenticated Service number, and I have set a domain name with the same public account as the currently accessed domain name, in addition, authorization is performed in a prompt box (to obtain user information) rather than silent authorization. My Development Process: 1. Call the interface open. weix... first, I confirm that my public account is the Authenticated Service number, and I have set a domain name with the same public account as the currently accessed domain name, in addition, authorization is performed in a prompt box (to obtain user information) rather than silent authorization.
My development process:
1. Call the interface http://open.weixin.qq.com/connect/oauth2/authorize? Appid = Public Account APPID & redirect_uri = My address & response_type = code & scope = snsapi_userinfo & state = 1 # wechat_redirect, and the code is obtained successfully.
2, the use of code to get access_token, call the https://api.weixin.qq.com/sns/oauth2/access_token? Appid = Public Account APPID & secret = Public Account APPSECRET & code = CODE & grant_type = authorization_code, and data such as access_token, refresh_token, and openid are obtained successfully.
3. Use the access_token obtained above to get the user https://api.weixin.qq.com/cgi-bin/user/info? Access_token = the obtained access_token & openid = the obtained openid & lang = zh_CN, but the obtained information here is an error message, errcode is 40001, errmsg: invalid credential, access_token is invalid or not latest hint: [25XmA020 ......].

The steps seem to be correct. Why cannot I obtain user information through the authorized access_token? I obtained the access_token and immediately used it to obtain the user information. It should not be the reason why the access_token times out. Which of the following experts knows what the problem is?

Reply content:

First, I confirm that my public account is the Authenticated Service number, and I have set a domain name with the same public account as the currently accessed domain name, in addition, authorization is performed in a prompt box (to obtain user information) rather than silent authorization.
My development process:
1. Call the interface http://open.weixin.qq.com/connect/oauth2/authorize? Appid = Public Account APPID & redirect_uri = My address & response_type = code & scope = snsapi_userinfo & state = 1 # wechat_redirect, and the code is obtained successfully.
2, the use of code to get access_token, call the https://api.weixin.qq.com/sns/oauth2/access_token? Appid = Public Account APPID & secret = Public Account APPSECRET & code = CODE & grant_type = authorization_code, and data such as access_token, refresh_token, and openid are obtained successfully.
3. Use the access_token obtained above to get the user https://api.weixin.qq.com/cgi-bin/user/info? Access_token = the obtained access_token & openid = the obtained openid & lang = zh_CN, but the obtained information here is an error message, errcode is 40001, errmsg: invalid credential, access_token is invalid or not latest hint: [25XmA020 ......].

The steps seem to be correct. Why cannot I obtain user information through the authorized access_token? I obtained the access_token and immediately used it to obtain the user information. It should not be the reason why the access_token times out. Which of the following experts knows what the problem is?

The interface for Obtaining user information needs to be authenticated

The error you reported should be caused by the invalid access_token. Is it because of the cache used to save access_token? In this case, it is recommended to clear the cache and try again. Http://www.weixin.com

Again, the interface for webpage authorization to obtain user information is

Http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html

Instead

Http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html

The AccessToken authorized by the web page and the AccessToken used to obtain user information are not one thing.

That is, the interface address in step 1 above should be

Https://api.weixin.qq.com/sns/userinfo

Instead

Https://api.weixin.qq.com/cgi-bin/user/info

Reference: https://github.com/thenbsp/wechat

10/6 I do not know the psychology of the person who stepped on the page, or whether the person who stepped on the page has carefully checked the Administrator's documents. If I think my answer is incorrect, please stand up and point out an error. Thank you!

Access_token is cached by yourself. You use an outdated

Obviously, the expiredate is 7200 seconds, but the accesstoken expires in less than 2 hours. How can I determine whether the accesstoken expires?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.