Twitter4jライブラリを使用してAndroidアプリからTwitterにログインしようとしていますが、コールバックが呼び出されるとクラッシュします...そしてこの画面が表示されます:ページは無責任ではありません
これは私のコードです:
public class TwitterLogin extends Activity {
/** Called when the activity is first created. */
Twitter twitter;
RequestToken requestToken;
/*
* Calls the OAuth login method as soon as its started
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
OAuthLogin();
}
/*
* - Creates object of Twitter and sets consumerKey and consumerSecret
* - Prepares the URL accordingly and opens the WebView for the user to provide sign-in details
* - When user finishes signing-in, WebView opens your activity back
*/
void OAuthLogin() {
try {
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(TwitterConstants.CONSUMER_KEY,TwitterConstants.CONSUMER_SECRET_KEY);
requestToken = twitter.getOAuthRequestToken(TwitterConstants.CALLBACK_URL);
Log.w("TwitterLogin requestToken callbackUrl: "+requestToken.toString());
// requestToken = twitter.getOAuthRequestToken(OAuth.OUT_OF_BAND);
// String pin = requestToken.getParameter(OAuth.OAUTH_VERIFIER);
String authUrl = requestToken.getAuthenticationURL();
Log.w("TwitterLogin requestToken authUrl: "+authUrl);
this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
Log.w("TwitterLogin despres del startActivity intent");
} catch (TwitterException ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
Log.e("in Main.OAuthLogin", ex.getMessage());
}
}
/*
* - Called when WebView calls your activity back.(This happens when the user has finished signing in)
* - Extracts the verifier from the URI received
* - Extracts the token and secret from the URL
*/
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.w("TwitterLogin dintre del onNewIntent");
Uri uri = intent.getData();
Log.w("TwitterLogin uri: "+uri.toString());
if (uri != null && uri.toString().startsWith(TwitterConstants.CALLBACK_URL)){
try {
String verifier = uri.getQueryParameter("oauth_verifier");
Log.w("TwitterLogin","onNewIntent oauth_verifier: "+verifier);
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
Log.w("TwitterLogin","onNewIntent accesToken: "+accessToken.toString());
String token = accessToken.getToken(), secret = accessToken.getTokenSecret();
displayTimeLine(token, secret); //after everything, display the first tweet
} catch (TwitterException ex) {
Log.e("Main.onNewIntent", "" + ex.getMessage());
}
}
}
/*
* Displays the timeline's first tweet in a Toast
*/
@SuppressWarnings("deprecation")
void displayTimeLine(String token, String secret) {
if (null != token && null != secret) {
List<Status> statuses = null;
try {
twitter.setOAuthAccessToken(token, secret);
statuses = twitter.getFriendsTimeline();
Toast.makeText(this, statuses.get(0).getText(), Toast.LENGTH_LONG)
.show();
} catch (Exception ex) {
Toast.makeText(this, "Error:" + ex.getMessage(),
Toast.LENGTH_LONG).show();
Log.d("Main.displayTimeline",""+ex.getMessage());
}
} else {
Toast.makeText(this, "Not Verified", Toast.LENGTH_LONG).show();
}
}
}
誰かが私を助けてくれるなら、私は2日間Twitterにログインしようとしていますが、これを解決する方法がわかりません。
ありがとう