0

I'm trying to integrate Twitter in my android application. I've checked Android10 and abhinavblog's code and I've changed just CONSUMER_KEY and CONSUMER_SECRET but I'm getting error from this block of code-

 @Override
    protected Void doInBackground(Void... params) {

        try {
            Log.i(TAG, "Retrieving request token from Google servers");
            final String url = provider.retrieveRequestToken(consumer, Constants.OAUTH_CALLBACK_URL);
            Log.i(TAG, "Popping a browser with the authorize URL : " + url);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
            context.startActivity(intent);
        } catch (Exception e) {
            Log.e(TAG, "Error during OAUth retrieve request token", e);
        }

        return null;
    }

Logcat error is-

 $02-22 11:24:48.012: W/KeyCharacterMap(515): No keyboard for id 0
    02-22 11:24:48.012: W/KeyCharacterMap(515): Using default keymap:              /system/usr/keychars/qwerty.kcm.bin
02-22 11:24:53.343: I/com.ecs.android.sample.twitter.PrepareRequestTokenActivity(515): Starting task to retrieve request token.
02-22 11:24:53.352: I/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): Retrieving request token from Google servers
02-22 11:24:54.374: D/dalvikvm(515): GC_FOR_MALLOC freed 10292 objects / 500672 bytes in 91ms
02-22 11:24:54.493: D/dalvikvm(515): GC_FOR_MALLOC freed 2064 objects / 289696 bytes in 71ms
02-22 11:24:54.503: D/NativeCrypto(515): Freeing OpenSSL session
02-22 11:24:55.022: W/DefaultRequestDirector(515): Authentication error: Unable to respond to any of these challenges: {}
02-22 11:24:55.022: I/global(515): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): Error during OAUth retrieve request token
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at com.ecs.android.sample.twitter.OAuthRequestTokenTask.doInBackground(OAuthRequestTokenTask.java:55)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at com.ecs.android.sample.twitter.OAuthRequestTokenTask.doInBackground(OAuthRequestTokenTask.java:1)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515):    at   java.lang.Thread.run(Thread.java:1096)

Why Authentication error: Unable to respond to any of these challenges: {} is empty?

I've give Read and Write permission On Twitter Application registration.

Any help would be greatly appreciated.

Geet taunk
  • 294
  • 1
  • 5
  • 19

1 Answers1

1

Your CONSUMER_KEY and CONSUMER_SECRET are not correct,they should be of application you have registered on twitter.

voidRy
  • 674
  • 9
  • 20
  • U r rite. But i have given correct keys, from the app i have registered on Twitter even i have tried Reset Keys option. And i also registered one new Application on Twitter and took that new keys and changed in my code than also i am getting the same error. I am stuck here totaly . please help – Geet taunk Feb 15 '12 at 07:43
  • Chk out this question u might get some solution , http://stackoverflow.com/questions/3315669/android-twitter-retrieverequesttoken-401-on-request-token – voidRy Feb 15 '12 at 08:32
  • Thanks for quick replys, can u plz tell me the use of CALLBACK URL. What should i write whil registering App to Twitter site, what should be in java file and what should be in XML file – Geet taunk Feb 15 '12 at 09:29
  • Try checking if you are connected to the internet. Restart your emulator. – Gadenkan Mar 26 '12 at 16:26