I am getting the following exception when I use scribe library for posting image to twitter

org.scribe.exceptions.OAuthException: Response body is incorrect. Can’t extract token and secret from this: '<?xml version=“1.0” encoding=“UTF-8”?

I am using scribe1.3.3 library.

I searched in google for this Exception ,but didnt find any solution.

I want to know about this Exception and how can I solve this issue.

The Exception I am getting is------------

03-05 15:52:24.810: E/AndroidRuntime(28777): org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and  secret from       this: '<?xml version="1.0" encoding="UTF-8"?>
03-05 15:52:24.810: E/AndroidRuntime(28777): <hash>
03-05 15:52:24.810: E/AndroidRuntime(28777):   <request>/oauth/access_token</request>
03-05 15:52:24.810: E/AndroidRuntime(28777):   <error>Invalid / expired Token</error>
03-05 15:52:24.810: E/AndroidRuntime(28777): </hash>

Source Code:

                            OAuthService oAuth = new ServiceBuilder()
    		        .provider(TwitterApi.class)
    		        .apiKey("xxxxxxxx")        // REPLACE WITH YOUR OWN!!!
    		        .apiSecret("yyyyyyyyyy")  // REPLACE WITH YOUR OWN!!!
    		        .callback(TwitterDialog.redirectedurl)             // REPLACE WITH YOUR OWN!!!
    		        .build();
 Uri uri = Uri.parse(TwitterDialog.redirectedurl);
		    Token requestToken = new Token( uri.getQueryParameter("oauth_token"),uri.getQueryParameter("oauth_verifier"));
		    Verifier verifier = new Verifier(uri.getQueryParameter("oauth_verifier"));
if(verifier!=null){
            	Log.e("verifier created","created");
            }
            
		    Token accesstoken=oAuth.getAccessToken(requestToken, verifier);
		    
		   
		    Log.e("raw resp", accesstoken.getRawResponse());

 if(accesstoken!=null){
		   
		   Log.e("hello","hhello");
         Log.e("access token","hi"+accesstoken.toString());
	    OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json");



    oAuth.signRequest(accesstoken, request);  // ENTER USER'S ACCESS TOKEN
   
// ADD MULTIPART FORM

    try
    {
        MultipartEntity entity = new MultipartEntity();

        entity.addPart("status", new StringBody("insert vacuous statement here"));       // THIS IS THE TWITTER MESSAGE
        entity.addPart("media", new FileBody(new File("/storage/sdcard0/HelloAlbum/1361964305003.jpg")));  // THIS IS THE PHOTO TO UPLOAD

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        entity.writeTo(out);

        request.addPayload(out.toByteArray());
        request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());
    }
    catch (UnsupportedEncodingException e) {e.printStackTrace();}
    catch (IOException e) {e.printStackTrace();}

// SEND REQUEST

    try {JSONObject response = new JSONObject (request.send().getBody());}
    catch (JSONException e) {Log.e("TOUR_APP_TAG", "JSONException Thrown: " + e.getMessage());}

   }

Logcat output:

     03-05 15:52:24.810: E/AndroidRuntime(28777): FATAL EXCEPTION: main
     03-05 15:52:24.810: E/AndroidRuntime(28777): org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret     from this: '<?xml version="1.0" encoding="UTF-8"?>
03-05 15:52:24.810: E/AndroidRuntime(28777): <hash>
03-05 15:52:24.810: E/AndroidRuntime(28777):   <request>/oauth/access_token</request>
03-05 15:52:24.810: E/AndroidRuntime(28777):   <error>Invalid / expired Token</error>
03-05 15:52:24.810: E/AndroidRuntime(28777): </hash>
03-05 15:52:24.810: E/AndroidRuntime(28777): '
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:103)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:84)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:89)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at com.android.twitter.TwitterActivity$1.onComplete(TwitterActivity.java:317)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at com.twitter.android.TwitterApp$1.handleMessage(TwitterApp.java:236)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at android.os.Looper.loop(Looper.java:137)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at android.app.ActivityThread.main(ActivityThread.java:5039)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at java.lang.reflect.Method.invokeNative(Native Method)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at java.lang.reflect.Method.invoke(Method.java:511)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-05 15:52:24.810: E/AndroidRuntime(28777): 	at dalvik.system.NativeStart.main(Native Method)

Try stepping outside of your library and looking at the steps of OAuth you’re executing and the responses you’re getting back. There are some hints in those responses.

sorry,I didnt understand what you are trying to explain to me.

have got any solution abt it, i am having same problem

Hi, i have the same issue all the time just when user try to login, any help? Please!

Hi,
org.scribe.exceptions.OAuthException: Response body is incorrect. Can’t extract token and secret from this: ‘Invalid request token’ Please help me…

ny solution fro this ?