本人初学android,跳转到一个新的页面之后获取微博信息总是获取失败,经过多次检查才发现数据传递错误,下面记录一下本人的实现方式,以备查询
授权页面,准备传值
Editor sharedata = getSharedPreferences("data", 0).edit();
sharedata.putString("openid", openid);
sharedata.putString("openkey", openkey);
sharedata.putString("accesstoken", accesstoken);
sharedata.commit();
信息获取页面,获取传递的信息
SharedPreferences sharedata = getSharedPreferences("data", 0);
String openid = sharedata.getString("openid", null);
String openkey = sharedata.getString("openkey", null);
String accesstoken = sharedata.getString("accesstoken", null);
初始化Oauth
oAuth=new OAuthV2(OAuthActivity.webUrl);
oAuth.setClientId(OAuthActivity.appID);
oAuth.setClientSecret(OAuthActivity.appKey);
oAuth.setOpenid(openid);
oAuth.setOpenkey(openkey);
oAuth.setAccessToken(accesstoken);
获取信息
StatusesAPI userOpt = new StatusesAPI("2.a");
try {
String info = userOpt.homeTimeline(oAuth, "json", "0", "0", "2", "0", "0x80");
((TextView)findViewById(R.id.textView)).setText(info.toString()); } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}