Scribe OAuthRequest to update status Twitter (Null object error)



Im trying to update twitter status using java with Scribe library (1.3).

Asking for a proctected resource as in the example works fine. (

However, I get the next error when im trying to write a tweet:

Exception in thread “main” java.lang.IllegalArgumentException: Cannot get String from a null object
at org.scribe.utils.Preconditions.check(
at org.scribe.utils.Preconditions.checkNotNull(
at org.scribe.utils.StreamUtils.getStreamContents(
at org.scribe.model.Response.parseBodyContents(
at org.scribe.model.Response.getBody(
at model.TwitterExample.main(

Highlight code parts:

OAuthService service = new ServiceBuilder()
Scanner in = new Scanner(;

// Obtain the Request Token
Token requestToken = service.getRequestToken();

Verifier verifier = new Verifier(in.nextLine());

// Trade the Request Token and Verfier for the Access Token
Token accessToken = service.getAccessToken(requestToken, verifier);</java>

String tweet = URLEncoder.encode(“First Tweet”,“UTF-8”);
String urlTweet=“”+tweet;

System.out.println("request: "+urlTweet);

OAuthRequest request2 = new OAuthRequest(Verb.POST, urlTweet);
service.signRequest(accessToken, request2);
System.out.println("REQUEST: " + request2.getUrl());
Response response2 = request2.send();

This exception throws in “response2.getBody()” print.

I have not been able to find the right solution to my problem in your discussions and external forums, so any help is appreciated.

Thank you in advance


Ok, I got it.

I noticed that the way requests works on twitter have changed just a month ago, and now it has to be used https instead of http.

I did some adjustments in my code before this question in reference to this, like using

instead of


Even so, I did not change this sentence of my code, which was the reason of my error.

String urlTweet=“”+tweet;


String urlTweet=“”+tweet;

I hope that if someone comes here with same problem can solve it with this relevant info.

Thanks eltabo for taking me to the right direction.