|
| 1 | +package org.scribe.examples; |
| 2 | + |
| 3 | +import java.util.Scanner; |
| 4 | + |
| 5 | +import org.scribe.builder.*; |
| 6 | +import org.scribe.builder.api.*; |
| 7 | +import org.scribe.model.*; |
| 8 | +import org.scribe.oauth.*; |
| 9 | + |
| 10 | +public class TrelloExample |
| 11 | +{ |
| 12 | + private static final String API_KEY = "your_api_key"; |
| 13 | + private static final String API_SECRET = "your_api_secret"; |
| 14 | + private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; |
| 15 | + public static void main(String[] args) |
| 16 | + { |
| 17 | + OAuthService service = new ServiceBuilder() |
| 18 | + .provider(TrelloApi.class) |
| 19 | + .apiKey(API_KEY) |
| 20 | + .apiSecret(API_SECRET) |
| 21 | + .build(); |
| 22 | + Scanner in = new Scanner(System.in); |
| 23 | + |
| 24 | + System.out.println("=== Trello's OAuth Workflow ==="); |
| 25 | + System.out.println(); |
| 26 | + |
| 27 | + // Obtain the Request Token |
| 28 | + System.out.println("Fetching the Request Token..."); |
| 29 | + Token requestToken = service.getRequestToken(); |
| 30 | + System.out.println("Got the Request Token!"); |
| 31 | + System.out.println(); |
| 32 | + |
| 33 | + System.out.println("Now go and authorize Scribe here:"); |
| 34 | + System.out.println(service.getAuthorizationUrl(requestToken)); |
| 35 | + System.out.println("And paste the verifier here"); |
| 36 | + System.out.print(">>"); |
| 37 | + Verifier verifier = new Verifier(in.nextLine()); |
| 38 | + System.out.println(); |
| 39 | + |
| 40 | + // Trade the Request Token and Verfier for the Access Token |
| 41 | + System.out.println("Trading the Request Token for an Access Token..."); |
| 42 | + Token accessToken = service.getAccessToken(requestToken, verifier); |
| 43 | + System.out.println("Got the Access Token!"); |
| 44 | + System.out.println("(if your curious it looks like this: " + accessToken + " )"); |
| 45 | + System.out.println(); |
| 46 | + |
| 47 | + // Now let's go and ask for a protected resource! |
| 48 | + System.out.println("Now we're going to access a protected resource..."); |
| 49 | + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); |
| 50 | + service.signRequest(accessToken, request); |
| 51 | + Response response = request.send(); |
| 52 | + System.out.println("Got it! Lets see what we found..."); |
| 53 | + System.out.println(); |
| 54 | + System.out.println(response.getBody()); |
| 55 | + |
| 56 | + System.out.println(); |
| 57 | + System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments