Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Wechat gets a hint of what to do with errcode 40002 errmsg invalid grant when getting access_token

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you Wechat to get access_token tips errcode 40002 errmsg invalid grant how to do, I believe most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!

Wechat obtains access_token through CURL, prompting errcode:40002errmsg:invalidgrant_type that the request for authorization operation can be successful, and passed the test using Wechat public platform API debugging tool. However, through the phpcurl request, getting AccessToken does prompt errcode:40002errmsg:invalidgrant_type all the time.

What about the Wechat 40002 problem?

The order of the requested URL parameters is in the order of the official document.

The following is the official description of the Wechat public platform.

Each time the official account calls the API, it may get a correct or incorrect return code. Developers can debug the interface according to the error code information and troubleshoot errors.

The global error code is described as follows:

40002 illegal credential types

It is initially believed that it is due to the incorrect application AppID, AppSecrect or callback domain name created on the open platform. If there are students who encounter similar problems, please share the solution.

Maybe your php code misspelled the granttype parameter.

Finally, it is found that the problem of request parameter error has been resolved.

Under normal circumstances, we basically cache access_token locally and invoke the cache within the cache time to ensure that the Wechat API is not requested within a certain period of time, the access efficiency of the submission feature, and so on. Recently encountered a problem, the website Wechat module authorization and so on are normal authorization access, but suddenly one day all Wechat authorization went to the police, all users showed authorization failure, chasing to the end is to obtain user information according to access_token this interface has been returning an error message. That is, access_token is invalid. However, the block generated by access_token is always cached according to the normal expiration time, and the cache expires on the request interface and locally. But how can it suddenly fail? The solution to this very strange problem:

1. Make sure that no one has modified the program of this Wechat module recently.

two。 Under the premise that no one modifies the update, go to the place where Wechat generates the access_token cache to write the file, and write the log file each time. Through a period of time log recording, analysis of my log found the problem. Sometimes there are interfaces that request access_token multiple times in a second. This is concurrency, that is, there are concurrent requests for access_token interfaces.

For the interface of concurrent request access_token, WeChat must have concurrent processing, but does our program consider concurrency when storing access_token cache? if not, sometimes the cache we store may not be the result of the last request, which will directly lead to the invalidation of access_token and the emergence of bug in related programs.

The above is all the content of this article "Wechat gets access_token tips on what to do with errcode 40002 errmsg invalid grant". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report