Question

This is the code i have currently, but I am unable to get the access tokens from my callback, any tips or hints will be appreciated.

                    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tweetr);
    Button tweetr = (Button)findViewById(R.id.tweetr);

    //create a new twitter configuration using user details
    tweetTwitter = new TwitterFactory().getInstance();
    tweetTwitter.setOAuthConsumer(TWIT_KEY, TWIT_SECRET);


        //create a twitter instance
   // tweetTwitter = new TwitterFactory(twitConf).getInstance();



    tweetr.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {


          dt.execute();

        }
    });



}


public class TweetTask extends AsyncTask<Object, Void, String> {
    @Override
    protected String doInBackground(Object... values) {
        /* try {
            //requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
        */
        try {
            requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
            String authUrl = requestToken.getAuthenticationURL();


            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


      return null;
    }


    @Override
    protected void onPostExecute(String result) {
        Log.d("URI", "DONE");
        super.onPostExecute(result);
    }




}



@Override
protected void onResume() {
    super.onResume();
    final Uri uri = getIntent().getData();
    if(uri != null ){

                Log.d("URI", uri.toString());

                Thread th = new Thread(){
                    public void run(){
                        AccessToken accessToken;

                        try {
                            String verifier = uri.getQueryParameter("oauth_verifier");
                            String oauthToken = uri.getQueryParameter("oauth_token");




                            accessToken = tweetTwitter.getOAuthAccessToken(verifier);
                            //String token = accessToken.getToken(), secret = accessToken.getTokenSecret();

                        } catch (TwitterException ex) {
                            Log.e("Main.onNewIntent", "" + ex.getMessage());
                        }


                    }};
                    th.start();
      }else
        Log.d("URI", "FAILED");         


    }
        }
Was it helpful?

Solution

I had to use the same requestToken in order to gain access with my app, so I had to edit the manifest file to allow only one instance of the activity to run after returning from webview login panel. That solved it for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top