Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b4ebc3

Browse files
committed
added API for xing.com incl. example
1 parent 78f57fb commit 7b4ebc3

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.scribe.builder.api;
2+
3+
import org.scribe.model.*;
4+
5+
public class XingApi extends DefaultApi10a
6+
{
7+
private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s";
8+
9+
@Override
10+
public String getAccessTokenEndpoint()
11+
{
12+
return "https://api.xing.com/v1/access_token";
13+
}
14+
15+
@Override
16+
public String getRequestTokenEndpoint()
17+
{
18+
return "https://api.xing.com/v1/request_token";
19+
}
20+
21+
@Override
22+
public String getAuthorizationUrl(Token requestToken)
23+
{
24+
return String.format(AUTHORIZE_URL, requestToken.getToken());
25+
}
26+
27+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 XingExample
11+
{
12+
private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me";
13+
14+
public static void main(String[] args)
15+
{
16+
OAuthService service = new ServiceBuilder()
17+
.provider(XingApi.class)
18+
.apiKey("097ccfd3ef25a1cb6d75")
19+
.apiSecret("e43364b2afd5d92f2ec28951a75bd8075f9cc221")
20+
.build();
21+
Scanner in = new Scanner(System.in);
22+
23+
System.out.println("=== Xing's OAuth Workflow ===");
24+
System.out.println();
25+
26+
// Obtain the Request Token
27+
System.out.println("Fetching the Request Token...");
28+
Token requestToken = service.getRequestToken();
29+
System.out.println("Got the Request Token!");
30+
System.out.println();
31+
32+
System.out.println("Now go and authorize Scribe here:");
33+
System.out.println(service.getAuthorizationUrl(requestToken));
34+
System.out.println("And paste the verifier here");
35+
System.out.print(">>");
36+
Verifier verifier = new Verifier(in.nextLine());
37+
System.out.println();
38+
39+
// Trade the Request Token and Verfier for the Access Token
40+
System.out.println("Trading the Request Token for an Access Token...");
41+
Token accessToken = service.getAccessToken(requestToken, verifier);
42+
System.out.println("Got the Access Token!");
43+
System.out.println("(if your curious it looks like this: " + accessToken + " )");
44+
System.out.println();
45+
46+
// Now let's go and ask for a protected resource!
47+
System.out.println("Now we're going to access a protected resource...");
48+
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
49+
service.signRequest(accessToken, request);
50+
Response response = request.send();
51+
System.out.println("Got it! Lets see what we found...");
52+
System.out.println();
53+
System.out.println(response.getBody());
54+
55+
System.out.println();
56+
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
57+
}
58+
59+
}

0 commit comments

Comments
 (0)