Skip to content

Commit 0fe6578

Browse files
added TumblrExample
1 parent 7fca6d5 commit 0fe6578

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 TumblrExample
11+
{
12+
private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info";
13+
14+
public static void main( String[] args )
15+
{
16+
OAuthService service = new ServiceBuilder()
17+
.provider( TumblrApi.class )
18+
.apiKey( "MY_CONSUMER_KEY" )
19+
.apiSecret( "MY_CONSUMER_SECRET" )
20+
.callback( "http://www.tumblr.com/connect/login_success.html" ) // OOB forbidden. We need an url and the better is on the tumblr website !
21+
.build();
22+
Scanner in = new Scanner( System.in );
23+
24+
System.out.println( "=== Tumblr'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 ,
43+
verifier );
44+
System.out.println( "Got the Access Token!" );
45+
System.out.println( "(if your curious it looks like this: " + accessToken + " )" );
46+
System.out.println();
47+
48+
// Now let's go and ask for a protected resource!
49+
System.out.println( "Now we're going to access a protected resource..." );
50+
OAuthRequest request = new OAuthRequest( Verb.GET ,
51+
PROTECTED_RESOURCE_URL );
52+
service.signRequest( accessToken ,
53+
request );
54+
Response response = request.send();
55+
System.out.println( "Got it! Lets see what we found..." );
56+
System.out.println();
57+
System.out.println( response.getBody() );
58+
59+
System.out.println();
60+
System.out.println( "Thats it man! Go and build something awesome with Scribe! :)" );
61+
}
62+
}

0 commit comments

Comments
 (0)