Skip to content

Instantly share code, notes, and snippets.

@dapurv5
Created May 14, 2013 15:40
Show Gist options
  • Save dapurv5/5576944 to your computer and use it in GitHub Desktop.
Save dapurv5/5576944 to your computer and use it in GitHub Desktop.
Twitter Stream API using Pablo's Scribe library
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TwitterApi;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
public class TwitterStreamOAuth {
private final static String ACCESS_TOKEN_KEY = "273014559-FevjK1FCxmHqXe1QIPcA4CnHFe6TAsJ0YefpITts";
private final static String ACCESS_TOKEN_SECRET = "PRNXlURgfEcCU6Fs4s7kG9QU6yyhJ8SNzGCDUf1mgI";
private final static String CONSUMER_KEY = "EJ79G5cmeb5e7mRX0WV3iA";
private final static String CONSUMER_SECRET = "RxfXjFcf8f3dsmc2bunJu0qgpGz6SXhUISHzgpeo9Zw";
private final static String URL = "https://stream.twitter.com/1/statuses/sample.json";
public static void main(String[] args){
OAuthService service = new ServiceBuilder().
provider(TwitterApi.class).
apiKey(CONSUMER_KEY).
apiSecret(CONSUMER_SECRET).
build();
Token requestToken = service.getRequestToken();
String authUrl = service.getAuthorizationUrl(requestToken);
Verifier verifier = new Verifier(authUrl);
System.out.println(requestToken);
Token accessToken = service.getAccessToken(requestToken, verifier); //this line gives error.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment