title: Android Twitter can't retrieve accestoken
body: <p>I get the error " Requrest token or token secret not set in server reply. The service provider you use is probably buggy. " when calling the </p>
  
  <p>provider.RetrieveAccesstoken(comsumer, verifier);</p>
  
  <p>But the weird thing is i only get this error sometimes. first my code worked en i posted a message. Then the next day i tried to reinstall the app on my </p>
  
  <p>home computer i got this error. back at my work station i got the same error again but after pressing the button that initiates the procedure it worked again and </p>
  
  <p>posted a message on Twitter. What the hell is going on?! could somebody explain?</p>
  
  <p>i run 2 emulators on android 2.2 it works more often on the WQVGA400 then on the WVGA800 emulator :S</p>
  
  <p>i also get the notification "Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required." </p>
  
  <p>Does this have to do something with my memory or storing the Token secrets? it sounds like the service is too busy to reply when contacting it.</p>
  
  <p>CODE</p>
  
  <p>For readibility i removed the exceptions and imports</p>
  
  <p>public class TestAgainActivity extends Activity {</p>
  
  <pre><code>private String CONSUMER_KEY = "xxxxx";
  private String CONSUMER_SECRET = "xxxxxxxxxxxx";
  private String CALLBACK_URL = "myapp://twit";
  private OAuthConsumer consumer; 
  private OAuthProvider provider;
  private String authUrl;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Button loginButton = new Button(this);
      loginButton = (Button)findViewById(R.id.button1);
      loginButton.setOnClickListener(login);
  
      consumer = new CommonsHttpOAuthConsumer(  
              CONSUMER_KEY, CONSUMER_SECRET);  
  
      provider = new DefaultOAuthProvider(
              "https://api.twitter.com/oauth/request_token",
              "https://api.twitter.com/oauth/access_token",  
              "https://api.twitter.com/oauth/authorize");  
  
  }
  private OnClickListener login = new OnClickListener() {
      public void onClick(View v) {
          AskOauth();
      }           
  
  };
  
  public void AskOauth(){
  
      try {
  
          authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
  
      Here i store the Consumer token and tokenSecret
          SharedPreferences savedTokens = getSharedPreferences("savedTokens", 0);
          SharedPreferences.Editor editor = savedTokens.edit();
          editor.putString("savedToken", consumer.getToken());
          editor.putString("savedTokenSecret", consumer.getTokenSecret());
          editor.commit();
  
          startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
  
      } catches{
  }
  
  }
  
  @Override
  protected void onResume() {
      // TODO Auto-generated method stub
      super.onResume();
  
      SharedPreferences savedTokens = getSharedPreferences("savedTokens", 0);
      String saved_token = savedTokens.getString("savedToken", "empty ShP");
      String saved_tokenSecret = savedTokens.getString("savedTokenSecret", "empty ShP");
      consumer.setTokenWithSecret(saved_token, saved_tokenSecret);
  
      System.out.println("consumer token "+consumer.getToken());
      System.out.println("consumer tokenSecret "+consumer.getTokenSecret());
  
  Uri uri = this.getIntent().getData();  
  
  
      if (uri != null &amp;&amp; uri.toString().startsWith(CALLBACK_URL)) {
  
        SharedPreferences savedTokens = getSharedPreferences("savedTokens", 0);
        String saved_token = savedTokens.getString("savedToken", "empty ShP");
    String saved_tokenSecret = savedTokens.getString("savedTokenSecret", "empty ShP");
        consumer.setTokenWithSecret(saved_token, saved_tokenSecret);
  
          String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);  
  
          try {
  
          Here i sometime get the error! 
          provider.retrieveAccessToken(consumer, verifier);
          AccessToken accesToken = new AccessToken(consumer2.getToken(), consumer2.getTokenSecret());
  
          Twitter twitter = new TwitterFactory().getInstance();
          twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
                  twitter.setOAuthAccessToken(accesToken);
                  Date d = new Date(System.currentTimeMillis());
                  String tweet = "This message is tweeted " + d.toLocaleString();
                  try {
                  twitter.updateStatus(tweet);
              } catch (TwitterException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }      
  
          } catch (OAuthMessageSignerException e1) {
          }
  </code></pre>