use of com.github.scribejava.core.builder.ServiceBuilder in project scribejava by scribejava.
the class MisfitExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
// Replace these with your own api key and secret
final String apiKey = "your client id";
final String apiSecret = "your client secret";
final OAuth20Service service = new ServiceBuilder().apiKey(apiKey).apiSecret(apiSecret).callback("http://example.com/callback/").scope("public,birthday,email,tracking,session,sleep").build(MisfitApi.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();
// Trade the Request Token and Verifier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
use of com.github.scribejava.core.builder.ServiceBuilder in project scribejava by scribejava.
the class NeteaseWeiboExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
// Replace these with your own api key and secret
final String apiKey = "your key";
final String apiSecret = "your secret";
final OAuth10aService service = new ServiceBuilder().apiKey(apiKey).apiSecret(apiSecret).build(NeteaseWeibooApi.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Grab a request token.
System.out.println("Fetching request token.");
final OAuth1RequestToken requestToken = service.getRequestToken();
System.out.println("Got it ... ");
System.out.println(requestToken.getToken());
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String oauthVerifier = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
use of com.github.scribejava.core.builder.ServiceBuilder in project scribejava by scribejava.
the class PinterestExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
// Replace these with your own api key and secret
final String apiKey = "your_app_id";
final String apiSecret = "your_app_secret";
final OAuth20Service service = new ServiceBuilder().apiKey(apiKey).apiSecret(apiSecret).scope("read_public,write_public,read_relationships,write_relationships").callback(// Add as valid callback in developer portal
"https://localhost:9000/").build(PinterestApi.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== Pinterest's OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken());
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
use of com.github.scribejava.core.builder.ServiceBuilder in project scribejava by scribejava.
the class Px500Example method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
final OAuth10aService service = new ServiceBuilder().apiKey("your-api-key").apiSecret("your-api-secret").build(Px500Api.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== 500Px's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
final OAuth1RequestToken requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
final String oauthVerifier = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
use of com.github.scribejava.core.builder.ServiceBuilder in project scribejava by scribejava.
the class RenrenExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
// Replace these with your own api key and secret
final String apiKey = "your api key";
final String apiSecret = "your api secret";
final OAuth20Service service = new ServiceBuilder().apiKey(apiKey).apiSecret(apiSecret).scope("status_update publish_feed").callback("http://your.doman.com/oauth/renren").build(RenrenApi.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
final Map<String, String> parameters = new HashMap<>();
parameters.put("method", "users.getInfo");
parameters.put("format", "json");
parameters.put("v", "1.0");
final List<String> sigString = new ArrayList<>(parameters.size() + 1);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
request.addQuerystringParameter(entry.getKey(), entry.getValue());
sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue()));
}
sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()));
Collections.sort(sigString);
final StringBuilder b = new StringBuilder();
for (String param : sigString) {
b.append(param);
}
b.append(apiSecret);
System.out.println("Sig string: " + b.toString());
request.addQuerystringParameter("sig", md5(b.toString()));
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
Aggregations