-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOAuthExample.java
More file actions
101 lines (73 loc) · 2.77 KB
/
OAuthExample.java
File metadata and controls
101 lines (73 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
*
* @category bluevia
* @package com.bluevia.examples
* @copyright Copyright (c) 2010 Telefonica I+D (http://www.tid.es)
* @author Bluevia <support@bluevia.com>
*
*
* BlueVia is a global iniciative of Telefonica delivered by Movistar
* and O2. Please, check out http://www.bluevia.com and if you need
* more information contact us at support@bluevia.com
*/
import java.util.Scanner;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import com.bluevia.commons.client.BVBaseClient.Mode;
import com.bluevia.commons.connector.http.oauth.OAuthToken;
import com.bluevia.commons.connector.http.oauth.RequestToken;
import com.bluevia.commons.exception.BlueviaException;
import com.bluevia.oauth.client.BVOauth;
/**
* OAuth API Class Examples
*
* @package com.bluevia.examples
*/
public class OAuthExample {
// Logger
private static Logger log = Logger.getLogger(OAuthExample.class.getName());
// API path (Mode Live/Sandbox)
public static Mode mode = Mode.SANDBOX;
// CREDENTIALS:
// User must DEFINE VALID VALUES FOR consumer token
// Consumer Key - Consumer Token
public static OAuthToken consumerToken = new OAuthToken("vw12012654505986", "WpOl66570544");
public static void main(String[] args) {
// Logger
BasicConfigurator.configure();
oauthProcess();
}
public static void oauthProcess() {
System.out.println("***** OAuthExample getRequestToken");
BVOauth client = null;
RequestToken response = null;
OAuthToken access = null;
try {
/*
* Define your phoneNumber to receive pin code through SMS
*/
String phoneNumber = "";
client = new BVOauth(mode, consumerToken.getToken(), consumerToken.getSecret());
response = client.getRequestTokenSmsHandshake(phoneNumber);
System.out.println("Token: " + response.getToken());
System.out.println("Secret: " + response.getSecret());
System.out.println("Url: " + response.getVerificationUrl());
/*
* oauth_verifier will be sent to the phoneNumber
*/
System.out.println("oauth_verifier: ");
Scanner in = new Scanner(System.in);
String oauth_verifier = in.nextLine();
access = client.getAccessToken(oauth_verifier, response.getToken(), response.getSecret());
System.out.println("Access Token:" + access.getToken());
System.out.println("Access Token Secret:" + access.getSecret());
} catch (BlueviaException e){
log.error(e.getMessage());
} catch (NumberFormatException e){
log.error(e.getMessage());
} finally {
// Close the client
if (client != null) client.close();
}
}
}