android开发新浪微博-OAuth认证时报错
来源:互联网 发布:淘宝奢侈品回收靠谱吗 编辑:程序博客网 时间:2024/05/03 14:58
首先上异常的截图:
报错的主要原因是没找到第三方的类。解决方法:项目右键Properties ------->Build Path------->Order And Export将第三方的jar包打勾。然后Clear自己的项目重新编译运行解决上述问题。详细请看截图
操作完上述步骤后Clear项目然后编译运行就OK了。
顺便把新浪OAuth认证源码给贴出来需要的哥们下载看看:
认证需要新浪的jar包。signpost-commonshttp4-1.2.1.1.jar signpost-core-1.2.1.1.jar下载地址:jar包下载
===================文件名: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: OAuth认证的实现</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";//替换成自己应用的key String consumerSecret = "458afde9c2ad61e9690296d8cca6488b";//也是自己的Secret String callBackUrl = "myapp://AuthActivity"; httpOauthConsumer = new CommonsHttpOAuthConsumer( 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); }}
源码地址:源码下载
- android开发新浪微博-OAuth认证时报错
- 新浪微博Android客户端开发之OAuth认证篇
- Oauth认证-新浪微博开发(上)
- Oauth认证-新浪微博开发(上)
- Oauth认证-新浪微博开发(下)
- Oauth认证-新浪微博开发(上)
- Oauth认证-新浪微博开发(下)
- android 新浪微博Oauth认证
- Android新浪微博OAuth授权认证
- 新浪微博Oauth认证
- 新浪微博OAuth认证
- 新浪微博OAuth认证
- 新浪微博开发(三)Oauth认证
- 新浪微博的Oauth认证过程
- 新浪微博OAuth 认证详解
- 如何实现新浪微博OAuth认证
- 新浪微博OAuth认证总结
- 新浪微博OAuth 认证详解
- 17周项目5:数组排序(指针法)
- 十年心得:一个优秀Android开发人员必须注意的10个误区
- Posix常用的数据类型
- Oracle数据导入导出imp/exp
- Android开发学习笔记(二)我的第一个Android应用
- android开发新浪微博-OAuth认证时报错
- 初学JDBC_第二节
- WPF制作窗口的启动和关闭动画
- 【天道酬勤】 腾讯、百度、网易游戏、华为Offer及笔经面经
- hdu 1325 Is It A Tree?
- 到主机的TCP/IP 连接失败解决方案
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务
- OpenCV_读取文件夹下的图片生成视频文件
- 网站优化中的用户体验