项目源代码:/detail/mrlixirong/3804385
import android.app.Activity;import android.content.Intent;import .Uri;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.*;/*** * @author mrlixirong* * -11-16**/public class WeiboQQTestActivity extends Activity {WeiboQQTestActivity wbqqta=this;RelativeLayout mainView=null;Button requestButton=null;Button verifierButton=null;EditText et=null;Button accessButton=null;TextView tv=null;Button addButton=null;Oauth oauth=null;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//初始化oauth=new Oauth("你的key","你的secret")oauth=new Oauth("","");//ui_init();setContentView(mainView);}void ui_init(){mainView=new RelativeLayout(this);requestButton=new Button(this);requestButton.setId(101);requestButton.setTextSize(18);requestButton.setText("gerRequest");RelativeLayout.LayoutParams lp1=new RelativeLayout.LayoutParams(-2,-2);lp1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);requestButton.setLayoutParams(lp1);mainView.addView(requestButton);verifierButton=new Button(this);verifierButton.setId(102);verifierButton.setTextSize(18);verifierButton.setText("getVerifier");RelativeLayout.LayoutParams lp2=new RelativeLayout.LayoutParams(-2,-2);lp2.addRule(RelativeLayout.CENTER_HORIZONTAL);verifierButton.setLayoutParams(lp2);mainView.addView(verifierButton);accessButton=new Button(this);accessButton.setId(103);accessButton.setTextSize(18);accessButton.setText("getAccess");RelativeLayout.LayoutParams lp3=new RelativeLayout.LayoutParams(-2,-2);lp3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);accessButton.setLayoutParams(lp3);mainView.addView(accessButton);addButton=new Button(this);addButton.setId(104);addButton.setTextSize(18);addButton.setText("发送一条信息");RelativeLayout.LayoutParams lp4=new RelativeLayout.LayoutParams(-2,-2);lp4.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);lp4.addRule(RelativeLayout.CENTER_HORIZONTAL);addButton.setLayoutParams(lp4);mainView.addView(addButton);et=new EditText(this);et.setId(105);et.setSingleLine();RelativeLayout.LayoutParams lp5=new RelativeLayout.LayoutParams(-1,-2);lp5.addRule(RelativeLayout.BELOW,accessButton.getId());et.setLayoutParams(lp5);mainView.addView(et);tv=new TextView(this);tv.setId(106);tv.setText("1、点击“getRequest”获取reqeust_token\n");RelativeLayout.LayoutParams lp6=new RelativeLayout.LayoutParams(-1,-2);lp6.addRule(RelativeLayout.BELOW,et.getId());tv.setLayoutParams(lp6);mainView.addView(tv);OnClickListener ocl=new OnClickListener(){@Overridepublic void onClick(View v) {if(v==requestButton){tv.setText("1、点击“getRequest”获取reqeust_token\n");if(oauth.oauth_consumer_key=="" || oauth.oauth_consumer_secret==""){tv.append("请在WeiboQQTestActivity里onCreate()函数,正确填写你的key和secret\n");}else{oauth=OauthClient.requestToken(oauth,wbqqta);if(oauth.status){tv.append("获取request_token成功\n");tv.append("request_token="+oauth.oauth_token+"\n");tv.append("request_token_secret="+oauth.oauth_token_secret+"\n");tv.append("2、点击“getVerifier”打开浏览器登陆qq获取verfier。\n");tv.append("3、获取verfier后,返回将其填入输入框。\n");tv.append("4、点击“getAccess”,获取access_token\n");}else{tv.append("获取request_token失败\n");}}}else if(v==verifierButton){if(oauth.status){Uri uri = Uri.parse("https://open./cgi-bin/authorize?oauth_token="+oauth.oauth_token); Intent intent = new Intent(Intent.ACTION_VIEW,uri); startActivity(intent); }else{tv.append("请先获取request_token\n");}}else if(v==accessButton){if(oauth.status && et.getText().toString().length()==6){oauth.oauth_verifier=et.getText().toString();oauth=OauthClient.accessToken(oauth,wbqqta);if(oauth.status){tv.append("获取access_token成功\n");tv.append("access_token="+oauth.oauth_token+"\n");tv.append("access_token_secret="+oauth.oauth_token_secret+"\n");tv.append("5、点击“发送一条信息”发布微博\n");}else{tv.append("获取request_token失败\n");}}else{tv.append("请先获取request_token,并输入正确的verifier\n");}}else if(v==addButton){//ip、jing、wei都可以为空tv.append(WeiboQQAPI.sendMessage(oauth, "这是1条测试信息", "", "", "", wbqqta));}}};requestButton.setOnClickListener(ocl);verifierButton.setOnClickListener(ocl);accessButton.setOnClickListener(ocl);addButton.setOnClickListener(ocl);}}