views:

149

answers:

1

Dear Android guys.

I am developing an application of Twitter -Client. i got lots of hint form this site. i write some come that is

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();
            }



}
}}

I compile fine and run this application it will reditect me at Twitter site for "Allow" permision. then i want to come back to my android application but i got error" could not found "SoftDroidbyDhrumil://twitterconnetcion?OuathToken=somoething"

Please Help me what do i write at my CallBack URL so i can come back from android browser to my application.

Thanks Dhrumil

+3  A: 

You need an Intent Filter to a specific URL that your app will handle on access.

So you will redirect to something like:

yourcustomscheme://witterconnetcion?OuathToken=somoething

In the middle of the following page, it's described http://developer.android.com/guide/topics/intents/intents-filters.html

Pentium10