Android third-party licensing (Sina Weibo blog)

Source: Internet
Author: User

Android third-party certified Sina Weibo, relative, is relatively simple, and Sina to an SDK and Sdkdemo, this demo package a lot, but they do not prepare to record this demo, but directly use the SDK

Also go to Sina official Download SDK, you go to search it, address does not give

1. Initialize Ssohandler

1 New AuthInfo (This, Constants.app_key, Constants.redirect_url, constants.scope); 2 New Ssohandler (this, mweiboauthinfo);

Some of these constants can be explained on the official website.

2. Start Licensing

1Mssohandler.authorize (NewMyweiboauthlistener (NewLoginweibogetuserinfolistener ())); 2 Private Static classMyweiboauthlistenerImplementsWeiboauthlistener {3 4         PrivateRequestlistener Mrequestuserinfolistener =NULL;5         6          PublicMyweiboauthlistener (Requestlistener requestuserinfolistener) {7              This. Mrequestuserinfolistener =Requestuserinfolistener;8         }9         Ten @Override One          Public voidOnCancel () { A             //TODO auto-generated Method Stub -Toast.maketext (Mcontext, "Weibo login canceled", Toast.length_short). Show (); -         } the  - @Override -          Public voidoncomplete (Bundle values) { -             //TODO auto-generated Method Stub +Maccesstoken =Oauth2accesstoken.parseaccesstoken (values); -             if(Maccesstoken.issessionvalid ()) { +                 //Save tokens to sharedpreferences AWeiboparameters weiboparameters =NewWeiboparameters ( at constants.app_key); -Weiboparameters.put ("Access_token", Maccesstoken.gettoken ()); -  -                 if(Mweiborunner = =NULL ){ -Mweiborunner =NewAsyncweiborunner ( - mcontext); in                 } -                  to                 if(Mrequestuserinfolistener = =NULL ){ +                     return; -                 } the Mweiborunner.requestasync (Weibo_userid_url, *Weiboparameters, "POST", $ mrequestuserinfolistener);Panax Notoginseng  -}Else { the                 //when you sign up for an application that is not signed correctly, you receive the Code, make sure the signature is correct +String code = values.getstring ("code", "" "); ALOG.I (TAG, "app signature is incorrect code =" +code); theToast.maketext (Mcontext, "Weibo certification failed", Toast.length_short). Show (); +  -             } $         } $  - @Override -          Public voidonweiboexception (weiboexception arg0) { the             //TODO auto-generated Method Stub - Wuyi         } the  -     } Wu  -  About /** $ * Get user information -      * @authorRecwert -      * -      */ A     Private Static classLoginweibogetuserinfolistenerImplementsRequestlistener { +      the @Override -          Public voidOnComplete (String result) { $             //TODO auto-generated Method Stub theJsonobject UserObject =json.parseobject (result); theString Weibouid = userobject.getstring ("UID"); the             if(Textutils.isempty (Weibouid)) { theLOG.E (TAG, "Weibo uid = null"); -                 return; in             } the              theLOG.I (TAG, "Weibo uid =" +weibouid); AboutUID =Weibouid; theWeiboparameters weiboparameters =Newweiboparameters (constants.app_key); theWeiboparameters.put ("UID", weibouid); theWeiboparameters.put ("Access_token", Maccesstoken.gettoken ()); +             if(Mweiborunner = =NULL ){ -Mweiborunner =NewAsyncweiborunner ( the mcontext);Bayi             } the              theMweiborunner.requestasync (Weibo_userinfo_url, Weiboparameters, "GET",NewMyweibohandleuserinfolistener ()); -         } -  the @Override the          Public voidonweiboexception (Weiboexception exception) { the             //TODO auto-generated Method Stub the exception.printstacktrace (); -              the         } the  the}

1 /**2 * Processing of acquired user information3      * @authorRecwert4      *5      */6     Private Static classMyweibohandleuserinfolistenerImplementsrequestlistener{7 8 @Override9          Public voidOnComplete (String result) {Ten             //TODO auto-generated Method Stub OneJsonobject UserData =json.parseobject (result); ANickname = userdata.getstring ("name"); -Headurl = userdata.getstring ("Profile_image_url"); -Sex = userdata.getstring ("Gender"); theLOG.I (TAG, "UID =" +uid); -LOG.I (TAG, "nickname =" +nickname); -LOG.I (TAG, "Headurl =" +headurl); -LOG.I (TAG, "sex =" +sex); +         } -  + @Override A          Public voidonweiboexception (Weiboexception exception) { at             //TODO auto-generated Method Stub - exception.printstacktrace (); -         } -          -}

As you can see, we just got Access_token in the first callback, and we need to get more information based on this access_token, such as asking for UserID and UserInfo.

1 Private Static Final String Weibo_userid_url = "Https://api.weibo.com/oauth2/get_token_info"; 2 Private Static Final String Weibo_userinfo_url = "Https://api.weibo.com/2/users/show.json";

Of course, more information gets the URL in the Sina official can check to see
Http://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI#OAuth2

Android third-party licensing (Sina Weibo blog)

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.