2

I try to use scribe for authorization with facebook and twitter. There is no problems with facebook. But when I try

requestToken = service.getRequestToken()

for twitter I get

Cannot get String from a null object

> ru.myx.ae3.exec.ExecErrorDefault
    > Cannot get String from a null object
    > java.lang.IllegalArgumentException
      : org.scribe.utils.Preconditions.check(Preconditions.java:84)
      : org.scribe.utils.Preconditions.checkNotNull(Preconditions.java:31)
      : org.scribe.utils.StreamUtils.getStreamContents(StreamUtils.java:22)
      : org.scribe.model.Response.parseBodyContents(Response.java:43)
      : org.scribe.model.Response.getBody(Response.java:69)
      : org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:60)
      : org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:40)
      : org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:45)
      : sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      : sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      : sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      : java.lang.reflect.Method.invoke(Method.java:606)

Could anybody help me to fix it?

  • Question closed. Change provider (TwitterApi.class) to provider (TwitterApi.Authenticate.class – user3246436 Jan 29 '14 at 5:37
4

Fortunately, Scribe has SSL support, you just need to use the correct TwitterAPI class inside the builder (the one intended for SSL connections:

final OAuthService service = new ServiceBuilder()
.provider(**TwitterApi.SSL.class**)
.apiKey(...)
.apiSecret(...)
.callback(...)
.build();

Worked for me like a charm :)

0

I had encountered this problem too...

What I did was I created a custom TwitterApi like bellow. For some reason, twitter oauth stopped supporting http and only supports ssl. see below.

import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.Token;


public class CustomTwitterApi extends DefaultApi10a {

private static final String AUTHORIZATION_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s";

public String getRequestTokenEndpoint() {
    return "https://api.twitter.com/oauth/request_token";
}

public String getAccessTokenEndpoint() {
    return "https://api.twitter.com/oauth/access_token";
}

public String getAuthorizationUrl(Token requestToken) {
    return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.