2010-09-10 11 views
2

Je développe une application de Twitter -Client. J'ai eu beaucoup de conseil sur ce site. Je viens d'écrire quelques qui estQue mettre à CALLBACK_URL dans twitter en utilisant Oauth de mon application android?

import oauth.signpost.OAuthProvider; 
import oauth.signpost.basic.DefaultOAuthProvider; 
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; 
import twitter4j.Status; 
import twitter4j.Twitter; 
import twitter4j.TwitterFactory; 
import twitter4j.http.AccessToken; 
import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.Button; 
import android.widget.Toast; 

public class TwitterConnetcion extends Activity { 

    private static final String APP ="OAUTH"; 

    private Twitter twitter; 

    private OAuthProvider provider; 

    private CommonsHttpOAuthConsumer consumer; 


    private String CONSUMER_KEY ="MyConsumerKey"; 

    private String CONSUMER_SECRET ="MyConsumersecrete"; 
    private String CALLBACK_URL ="SoftDroidbyDhrumil://twitterconnetcion";///SoftDroid is my twitter //Apllication that i registered in Twitter site 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     try { 
      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"); 

      String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL); 
      Log.i("Dhrumil",authUrl); 
      Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show(); 

      this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl))); 
      Log.i("Dhrumil","Browser Start"); } catch (Exception e) { 
      Log.i("Dhrumil"+APP, e.toString()); 
      Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); 
    } 
    protected void onNewIntent(Intent intent) { 
     // TODO Auto-generated method stub 
     super.onNewIntent(intent); 

     Uri uri = intent.getData(); 
     if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { 

       String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER); 

       Log.i("Dhrumil verifier",verifier); 
       try { 
         // this will populate token and token_secret in consumer 
         provider.retrieveAccessToken(consumer, verifier); 

         // TODO: you might want to store token and token_secret in you app settings!!!!!!!! 
         AccessToken a = new AccessToken(consumer.getToken(), consumer.getTokenSecret()); 
         Log.i("Dhrumil AccessToken",a.toString()); 
         // initialize Twitter4J 
         twitter = new TwitterFactory().getInstance(); 
         twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
         twitter.setOAuthAccessToken(a); 

         // create a tweet 
         Date d = new Date(System.currentTimeMillis()); 
         String tweet = "#OAuth working! " + d.toLocaleString(); 

         // send the tweet 
         twitter.updateStatus(tweet); 

         // feedback for the user... 

         Toast.makeText(this, tweet, Toast.LENGTH_LONG).show(); 


       } catch (Exception e) { 
         Log.e(APP, e.getMessage()); 
         Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); 
       } 



    } 
    }} 

je compile bien et exécuter cette application, il me rediriger sur le site Twitter pour l'autorisation « Autoriser ». Ensuite, je veux revenir à mon application Android, mais j'ai eu une erreur "n'a pas pu trouver" SoftDroidbyDhrumil: // twitterconnetcion? OuathToken = quelque chose "

Qu'est-ce que j'écris à mon URL CallBack afin que je puisse revenir de navigateur Android à ? ma demande

Répondre