我正在尝试使用 twitter 4j 加载 twitter 页面,但未加载 twitter 页面我已经注册了我的应用程序并在此处获取我的消费者密钥和消费者密钥这是我的代码
package a.a.a;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
public class StatusListActivity extends ListActivity{
private Otweet app;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
app=(Otweet)getApplication();
setContentView(R.layout.main);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if(!app.isAuthorized())
{
beginAuthorization();
}
else
{
}
}
public void beginAuthorization()
{
Intent intent=new Intent(StatusListActivity.this,AuthorizationActivity.class);
startActivity(intent);
}
}
这是授权活动
package a.a.a;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class AuthorizationActivity extends Activity{
private Otweet app;
WebView WV;
Twitter twitter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
app=(Otweet)getApplication();
setContentView(R.layout.authorization_view);
WV=(WebView)findViewById(R.id.web_view);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
//twitter=new TwitterFactory().getInstance();
//twitter.setOAuthConsumer("C6lqBhtUcC5f9wuauwoxag", "BttswrGyCxaeLgOZAdtfSqlbEg1uiw6xnuXD4y2rcjE");
String authURL=app.BeginAuthorization();
WV.loadUrl(authURL);
}
}
这是 otweet 活动
public class Otweet extends Application {
private OAuthHelper authhelper;
private Twitter twitter;
private RequestToken currentRequestToken;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
authhelper=new OAuthHelper(this);
twitter=new TwitterFactory().getInstance();
authhelper.configureOAuth(twitter);
}
public boolean isAuthorized()
{
return authhelper.hasAccessToken();
}
public String BeginAuthorization()
{
try
{
if(null==currentRequestToken)
{
currentRequestToken=twitter.getOAuthRequestToken();
}
return currentRequestToken.getAuthorizationURL();
}
catch (TwitterException e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}
函数开始授权总是返回 null。