I'm pretty new to Scribe but when i try to auth through Twitter a weird error rises up.
My code is pretty much the same than the TwitterExample:
OAuthService service = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey("XXXXXXXXXXXXXX<<custom>>XXXXXXXXXXXXXXX")
.apiSecret("YYYYYYYYYYYYYYYY<<custom>>YYYYYYYYYYYYYYYYYYYYYYYYY")
.debug()
.build();
Token requestToken = service.getRequestToken();
Log.i("OAUTH LINK", service.getAuthorizationUrl(requestToken));
Verifier verifier = new Verifier("verifier you got from the user");
Token accessToken = service.getAccessToken(requestToken, verifier);
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
response = request.send();
Log.i("OAUTH RESPONSE",response.getBody());
And the debug output returned is:
I/System.out(1776): obtaining request token from http://api.twitter.com/oauth/request_token
I/System.out(1776): setting oauth_callback to oob
I/System.out(1776): generating signature...
I/System.out(1776): using base64 encoder: CommonsCodec
I/System.out(1776): base string is: POST&http%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Doob%26oauth_consumer_key%3DXXXXXXXXXXXXXXXXXXXXX%26oauth_nonce%3D1095830595%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1391024186%26oauth_version%3D1.0
I/System.out(1776): signature is: In0u/SlHz9cr5NLAQK56kALJ3hI=
I/System.out(1776): appended additional OAuth parameters: { oauth_callback -> oob , oauth_signature -> In0u/SlHz9cr5NLAQK56kALJ3hI= , oauth_version -> 1.0 , oauth_nonce -> 1095830595 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> XXXXXXXXXXXXXXXXXXXX , oauth_timestamp -> 1391024186 }
I/System.out(1776): using Http Header signature
I/System.out(1776): sending request...
D/dalvikvm(1776): GC_FOR_ALLOC freed 174K, 3% free 13188K/13575K, paused 134ms
I/System.out(1776): response status code: 403
I/System.out(1776): response body:
W/System.err(1776): java.lang.IllegalArgumentException: Response body is incorrect. Can't extract a token from an empty string
W/System.err(1776): at org.scribe.utils.Preconditions.check(Preconditions.java:84)
W/System.err(1776): at org.scribe.utils.Preconditions.checkEmptyString(Preconditions.java:44)
W/System.err(1776): at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:26)
W/System.err(1776): at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:64)
W/System.err(1776): at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:40)
W/System.err(1776): at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:45)
W/System.err(1776): at com.roundmesa.twitter.TwitterLoginTask.doInBackground(TwitterLoginTask.java:45)
W/System.err(1776): at com.roundmesa.twitter.TwitterLoginTask.doInBackground(TwitterLoginTask.java:1)
W/System.err(1776): at android.os.AsyncTask$2.call(AsyncTask.java:264)
W/System.err(1776): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(1776): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(1776): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
W/System.err(1776): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
W/System.err(1776): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err(1776): at java.lang.Thread.run(Thread.java:856)
Somebody else found this error? (It must be absolutely for newbies but i couldn't find nothing similar out there...
Thanks!
This happened to me as well recently. The problem is that Twitter started refusing regular connections and by default, Scribe does not use SSL. The fix is fairly simple: instead of using the regular Scribe Twitter API class, use the SSL one:
final OAuthService service = new ServiceBuilder()
.provider(**TwitterApi.SSL.class**)
.apiKey(...)
.apiSecret(...)
.callback(...)
.build();