Created
January 28, 2011 21:35
-
-
Save lindenb/801016 to your computer and use it in GitHub Desktop.
Simple test for OAUth with the Scribe library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pierre Lindenbaum | |
* Simple test for OAUth with the Scribe library | |
*/ | |
import javax.swing.JOptionPane; | |
import org.scribe.builder.ServiceBuilder; | |
import org.scribe.builder.api.TwitterApi; | |
import org.scribe.model.OAuthRequest; | |
import org.scribe.model.Response; | |
import org.scribe.model.Token; | |
import org.scribe.model.Verb; | |
import org.scribe.model.Verifier; | |
import org.scribe.oauth.OAuthService; | |
public class TestOAuth | |
{ | |
private static final String AUTHORIZE_URL = "https://twitter.com/oauth/authorize?oauth_token="; | |
private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com/1/account/verify_credentials.xml"; | |
public static void main(String[] args) | |
{ | |
try | |
{ | |
Token accessToken=null; | |
OAuthService service=new ServiceBuilder() | |
.provider(TwitterApi.class) | |
.apiKey("Ix0FJb7uHsNPW2le8RO5Q") | |
.apiSecret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") | |
.build(); | |
for(int i=0;i< 5;++i) | |
{ | |
// Obtain the Request Token | |
if(accessToken==null) | |
{ | |
Token requestToken = service.getRequestToken(); | |
System.out.println(AUTHORIZE_URL + requestToken.getToken()); | |
String oauth_token=JOptionPane.showInputDialog(null); | |
Verifier verifier = new Verifier(oauth_token); | |
accessToken = service.getAccessToken(requestToken, verifier); | |
} | |
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); | |
service.signRequest(accessToken, request); | |
Response response = request.send(); | |
System.out.println(response.getBody()); | |
} | |
} | |
catch (Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment