我试过这段代码: http://code.google.com/p/weibo-android-sdk/source/browse/example/src/com/weibo/android/example/AuthorizeActivity.java?r=12 您可以从http://code.google.com/p/android-weibo-sdk/downloads/list获取整个应用程序 授权工作,但后来我从代码中更改了appkey和appsecret,以及微博给我的开发者帐户,在我更改后有以下代码:
private static final String CONSUMER_KEY = "1415745064";// Replace a developer's appkey, for example, "1646212960";
private static final String CONSUMER_SECRET = "8cf118d44c9881b9d1cbf2c4eb957c57";// Replace a developer's appkey, e.g. "94098772160b6f8ffc1315374d8861f9";
private String username = "";
private String password = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mToken = (TextView) this.findViewById(R.id.tvToken);
mLogin = (Button) this.findViewById(R.id.btnLogin);
mLogin.setText("oauth!");
mLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (v == mLogin) {
Weibo weibo = Weibo.getInstance();
Log.d("onclick", "onclick");
weibo.setupConsumerConfig(CONSUMER_KEY, CONSUMER_SECRET);
// Oauth2.0
// Implicit authorization and authentication
Log.d("onclick", "dupa setupconsumerconfig");
weibo.setRedirectUrl("http://www.sina.com");
// Here the callback page content should replace the corresponding application callback page with appkey
// Application callback page landing Sina microblogging development platform developers
// Into my application - Application Details - Application Information - Senior - authorization settings - application callback page set up
// and view
// Application callback page is not empty
Log.d("onclick", "dupa set redirecturl");
weibo.authorize(AuthorizeActivity.this, new AuthDialogListener());
Log.d("onclick", "dupa autorize");
}
}
});
}
其余代码是相同的,但是我没有向我显示可以写入我的电子邮件和密码登录的对话框,而是出现了一个错误的对话框。有些用中文写,不能理解id,而不是说:(错误:redirect_uri)不匹配)。