Android imitation Sina Weibo oauth2.0 authorization interface implementation code (2)

Oauth2.0 authorization interface, approximate flow chart:

Prerequisite preparation:

Apply for appkey and appsecret on Sina open platform: http://open.weibo.com/. Familiar with oauth2.0 protocol, relevant knowledge: http://www.ruanyifeng.com/blog/2014/05/oauth_ 2_ 0.html oauth2 access_ Token interface: http://open.weibo.com/wiki/OAuth2/access_ token

Code explanation

The general idea is as follows: establish a WebView loading authorization interface. Please refer to constants.java for the authorization callback address. This method will be called back when the page is loaded. If the user agrees (enter his microblog account password), he will successfully obtain the code, and then send an asynchronous post request to obtain access_ Token if access is obtained successfully_ For token information, use SharedPreferences to save all important information and jump to the main interface. The request parameters of asynchronous post settings must follow the access of oauth2_ The request parameters required in the token interface correspond one by one. Access obtained here_ Token is a necessary request parameter for each interface.

The asynchronous request class weiborestclient.java here sends HTTP requests asynchronously and processes the response HTTP requests in the callback function. The process is not carried out in the UI thread. The thread pool is used to manage the concurrency and support get / post requests

Layout of oauthactivity webview.xml

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>