· 8 years ago · Jan 16, 2017, 05:26 AM
1@Override
2protected void onCreate(Bundle savedInstanceState) {
3 super.onCreate(savedInstanceState);
4 setContentView(R.layout.activity_authentication);
5
6 final WebView wvAuthorise = (WebView) findViewById(R.id.wvAuthorise);
7 wvAuthorise.getSettings().setJavaScriptEnabled(true);
8 wvAuthorise.setWebViewClient(new MyWebViewClient(wvAuthorise));
9
10 final OAuth10aService service = new ServiceBuilder() //1. Create oauthservice object
11 .apiKey(WithingsApi.getKey())
12 .apiSecret(WithingsApi.getSecret())
13 .signatureType(SignatureType.QueryString)
14 .build(WithingsApi.instance());
15
16 new Thread(new Runnable() {
17 public void run() {
18 try {
19 requestToken = service.getRequestToken(); //2. Guna service to get TOKEN
20 Log.v("TOKEN hang: ", requestToken.toString()); //return oauth_token dan oauth_secret_token
21 } catch (IOException e) {
22 e.printStackTrace();
23 } catch (InterruptedException e) {
24 e.printStackTrace();
25 } catch (ExecutionException e) {
26 e.printStackTrace();
27 }
28 final String authURL = service.getAuthorizationUrl(requestToken); //3. Guna TOKEN to get AUTHORIZE URL
29 wvAuthorise.post(new Runnable() { //return oauth_token dan user id
30 @Override
31 public void run() {
32 //Log.v("Authorize urlnya : " , authURL);
33 wvAuthorise.loadUrl(authURL);
34 }
35 });
36
37 }
38 }).start();
39
40}