Android development Sina Weibo-OAuth authentication error

Source: Internet
Author: User
Tags key string oauth

First, the error is reported because the third-party classes are not found. Solution: Right-click the project Properties -------> Build Path -------> Order And Export to check the third-party jar package. Then Clear your project and re-compile and run it to solve the above problem. For details, see the above steps and then Clear the project and compile and run it. By the way, I posted the source code of Sina OAuth authentication to the buddies who needed it and downloaded it: Sina's jar package is required for authentication. Signpost-commonshttp4-1.2.1.1.jar signpost-core-1.2.1.1.jar: jar package download ============================ file name: AuthActivity. java ========================== package OAuth4Sina.com; import java. util. sortedSet; import oauth. signpost. OAuthProvider; import oauth. signpost. basic. defaultOAuthProvider; import oauth. signpost. commonshttp. commonsHttpOAuthConsumer; import oauth. signpost. exception. OAuthCommunicationException; import oauth. signpost. exception. OAuthExpectationFailedException; import oauth. signpost. exception. OAuthMessageSignerException; import oauth. signpost. exception. OAuthNotAuthorizedException; import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. textView;/***** <p> Title: AuthActivity. java </p> * <p> Description: Implementation of OAuth authentication </p> * <p> Copyright: Copyright (c) 2011 </p> * <p> Company: CTX Teachnology </p> * <p> CreateTime: 2012-12-22 04:21:04 </p> ** @ author YGC * @ version V1.0 * @ since JDK1.6 */public class AuthActivity extends Activity {CommonsHttpOAuthConsumer httpOauthConsumer; OAuthProvider httpOauthprovider; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); Button btn2 = (Button) findViewById (R. id. btn); btn2.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {try {String consumerKey = "434313181"; // replace it with your own key String consumerSecret = "secret "; // also your own Secret String callBackUrl = "myapp: // AuthActivity"; httpOauthConsumer = new consumer (consumerKey, consumerSecret); httpOauthprovider = new DefaultOAuthProvider ("http://api.t.sina.com.cn/oauth/request_token", "http://api.t.sina.com.cn/oauth/access_token ", "http://api.t.sina.com.cn/oauth/authorize"); String authUrl = httpOauthprovider. retrieveRequestToken (httpOauthConsumer, callBackUrl); startActivity (new Intent (Intent. ACTION_VIEW, Uri. parse (authUrl); int B = 4;} catch (Exception e) {String s = e. getMessage () ;}}) ;}@ Override protected void onNewIntent (Intent intent) {super. onNewIntent (intent); Uri uri = intent. getData (); String verifier = uri. getQueryParameter (oauth. signpost. OAuth. OAUTH_VERIFIER); try {httpOauthprovider. setOAuth10a (true); httpOauthprovider. retrieveAccessToken (httpOauthConsumer, verifier);} catch (OAuthMessageSignerException ex) {ex. printStackTrace ();} catch (OAuthNotAuthorizedException ex) {ex. printStackTrace ();} catch (OAuthExpectationFailedException ex) {ex. printStackTrace ();} catch (OAuthCommunicationException ex) {ex. printStackTrace ();} SortedSet <String> user_id = httpOauthprovider. getResponseParameters (). get ("user_id"); String userId = user_id.first (); String userKey = httpOauthConsumer. getToken (); String userSecret = httpOauthConsumer. getTokenSecret (); TextView text = (TextView) findViewById (R. id. text); text. setText ("suerId:" + userId + "/userKey:" + userKey + "/userSecret:" + userSecret );}}

Related Article

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.