Added classes for manage authentication and retrieve data to/from fitbit... but the code needs some mods!
This commit is contained in:
Binary file not shown.
Binary file not shown.
193
.idea/workspace.xml
generated
193
.idea/workspace.xml
generated
@@ -2,10 +2,10 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="78e01e81-87ab-43aa-be01-5489e21c7fc2" name="Default" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/tests/TestLights.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.gradle/4.4/fileHashes/fileHashes.bin" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/4.4/fileHashes/fileHashes.bin" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.gradle/4.4/fileHashes/fileHashes.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/4.4/fileHashes/fileHashes.lock" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/device/hue.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/device/Hue.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/manage/rest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/manage/Rest.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
|
||||
</list>
|
||||
<ignored path="$PROJECT_DIR$/.gradle/" />
|
||||
<ignored path="$PROJECT_DIR$/build/" />
|
||||
@@ -86,24 +86,23 @@
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file leaf-file-name="Hue.java" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/device/Hue.java">
|
||||
<file leaf-file-name="AuthFITBIT.java" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/AuthFITBIT.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="240">
|
||||
<caret line="18" column="5" lean-forward="true" selection-start-line="18" selection-start-column="5" selection-end-line="18" selection-end-column="5" />
|
||||
<state>
|
||||
<caret column="15" lean-forward="true" selection-start-column="15" selection-end-column="15" />
|
||||
<folding>
|
||||
<element signature="e#310#311#0" expanded="true" />
|
||||
<element signature="e#362#363#0" expanded="true" />
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="TestLights.java" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/tests/TestLights.java">
|
||||
<file leaf-file-name="UserData.java" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/UserData.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="8" column="17" selection-start-line="8" selection-start-column="17" selection-end-line="8" selection-end-column="17" />
|
||||
<state relative-caret-position="255">
|
||||
<caret line="15" column="54" selection-start-line="15" selection-start-column="54" selection-end-line="15" selection-end-column="54" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
@@ -301,9 +300,9 @@
|
||||
</option>
|
||||
<option name="modificationStamps">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="6110052192246" />
|
||||
<entry key="$PROJECT_DIR$" value="6110144149611" />
|
||||
<entry key="$PROJECT_DIR$/.gradle" value="0" />
|
||||
<entry key="$PROJECT_DIR$/build.gradle" value="2680631353" />
|
||||
<entry key="$PROJECT_DIR$/build.gradle" value="384538824" />
|
||||
<entry key="$PROJECT_DIR$/gradle/wrapper/gradle-wrapper.properties" value="2083459160" />
|
||||
<entry key="$PROJECT_DIR$/settings.gradle" value="2435099665" />
|
||||
</map>
|
||||
@@ -489,11 +488,16 @@
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/build.gradle" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/device/hue.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/tests/Test.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/device/Hue.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/tests/TestLights.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/manage/OAuth2ClientCredentials.java" />
|
||||
<option value="$PROJECT_DIR$/build.gradle" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/manage/FITBITUrl.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/manage/AuthFITBIT.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/manage/Data.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/manage/UserData.java" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -518,7 +522,7 @@
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="Scope" />
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
@@ -572,8 +576,8 @@
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="AndroidView" />
|
||||
<pane id="Scope" />
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
@@ -719,7 +723,8 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1527511421271</updated>
|
||||
<workItem from="1527511465296" duration="493000" />
|
||||
<workItem from="1527514123141" duration="7701000" />
|
||||
<workItem from="1527514123141" duration="8177000" />
|
||||
<workItem from="1527603873798" duration="4758000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Updated build gradle Added functions ph. hue">
|
||||
<created>1527518149240</created>
|
||||
@@ -728,7 +733,14 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1527518149240</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<task id="LOCAL-00002" summary="Seems that the test for lights passes, tried with the emulator">
|
||||
<created>1527522377670</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1527522377670</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="3" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TestHistory">
|
||||
@@ -741,9 +753,12 @@
|
||||
<history-entry file="TestLights - 2018.05.28 at 17h 38m 24s.xml">
|
||||
<configuration name="TestLights" configurationId="JUnit" />
|
||||
</history-entry>
|
||||
<history-entry file="TestLights - 2018.05.28 at 17h 44m 00s.xml">
|
||||
<configuration name="TestLights" configurationId="JUnit" />
|
||||
</history-entry>
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="8194000" />
|
||||
<option name="totallyTimeSpent" value="13428000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
|
||||
@@ -751,33 +766,33 @@
|
||||
<layout>
|
||||
<window_info anchor="right" id="Palette" order="3" />
|
||||
<window_info anchor="bottom" id="TODO" order="6" />
|
||||
<window_info anchor="bottom" id="Messages" />
|
||||
<window_info anchor="right" id="Palette	" order="3" />
|
||||
<window_info id="Image Layers" order="2" />
|
||||
<window_info anchor="right" id="Capture Analysis" order="3" />
|
||||
<window_info anchor="bottom" id="Event Log" order="7" side_tool="true" weight="0.32838285" />
|
||||
<window_info anchor="right" id="Maven Projects" order="3" />
|
||||
<window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Version Control" order="7" weight="0.32838285" />
|
||||
<window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.32838285" />
|
||||
<window_info anchor="bottom" id="Terminal" order="7" />
|
||||
<window_info id="Capture Tool" order="2" />
|
||||
<window_info anchor="right" id="Palette	" order="9" />
|
||||
<window_info id="Image Layers" order="6" />
|
||||
<window_info anchor="right" id="Capture Analysis" order="4" />
|
||||
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" weight="0.32838285" />
|
||||
<window_info anchor="right" id="Maven Projects" order="5" />
|
||||
<window_info anchor="bottom" id="Database Changes" order="9" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Version Control" order="11" weight="0.32838285" />
|
||||
<window_info anchor="bottom" id="Run" order="2" weight="0.32838285" />
|
||||
<window_info anchor="bottom" id="Terminal" order="8" />
|
||||
<window_info id="Capture Tool" order="5" />
|
||||
<window_info id="Designer" order="2" />
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2579425" />
|
||||
<window_info anchor="bottom" id="Build" order="7" weight="0.3290938" />
|
||||
<window_info anchor="right" id="Database" order="3" />
|
||||
<window_info anchor="right" id="Gradle" order="3" weight="0.32980332" />
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.26172465" />
|
||||
<window_info anchor="bottom" id="Build" order="7" weight="0.32838285" />
|
||||
<window_info anchor="right" id="Database" order="7" />
|
||||
<window_info anchor="right" id="Gradle" order="6" weight="0.32980332" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
|
||||
<window_info id="UI Designer" order="2" />
|
||||
<window_info anchor="right" id="Theme Preview" order="3" />
|
||||
<window_info id="Favorites" order="2" side_tool="true" />
|
||||
<window_info id="UI Designer" order="3" />
|
||||
<window_info anchor="right" id="Theme Preview" order="8" />
|
||||
<window_info id="Favorites" order="4" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
||||
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||
<window_info anchor="bottom" id="Messages" order="10" />
|
||||
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Find" order="1" />
|
||||
</layout>
|
||||
</component>
|
||||
@@ -789,22 +804,33 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Updated build gradle Added functions ph. hue" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Updated build gradle Added functions ph. hue" />
|
||||
<MESSAGE value="Seems that the test for lights passes, tried with the emulator" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Seems that the test for lights passes, tried with the emulator" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/device/Hue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state>
|
||||
<caret lean-forward="true" />
|
||||
<state relative-caret-position="306">
|
||||
<caret line="18" column="5" lean-forward="true" selection-start-line="18" selection-start-column="5" selection-end-line="18" selection-end-column="5" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/tests/TestLights.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="357">
|
||||
<caret line="21" column="22" selection-start-line="21" selection-start-column="22" selection-end-line="21" selection-end-column="22" />
|
||||
<folding>
|
||||
<element signature="e#310#311#0" expanded="true" />
|
||||
<element signature="e#362#363#0" expanded="true" />
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/settings.gradle">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/device/Hue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state>
|
||||
<caret lean-forward="true" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/Rest.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
@@ -821,28 +847,77 @@
|
||||
<state relative-caret-position="-1136" />
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/build.gradle">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/tests/TestLights.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="221">
|
||||
<caret line="13" column="14" selection-start-line="13" selection-start-column="14" selection-end-line="13" selection-end-column="14" />
|
||||
<state relative-caret-position="323">
|
||||
<caret line="21" column="22" selection-start-line="21" selection-start-column="22" selection-end-line="21" selection-end-column="22" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/device/Hue.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="240">
|
||||
<caret line="18" column="5" lean-forward="true" selection-start-line="18" selection-start-column="5" selection-end-line="18" selection-end-column="5" />
|
||||
<state relative-caret-position="17">
|
||||
<caret line="18" column="5" selection-start-line="18" selection-start-column="5" selection-end-line="18" selection-end-column="5" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/OAuth2ClientCredentials.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="308">
|
||||
<caret line="25" lean-forward="true" selection-start-line="25" selection-end-line="25" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/build.gradle">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="374">
|
||||
<caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/Data.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="187">
|
||||
<caret line="11" column="21" lean-forward="true" selection-start-line="11" selection-start-column="21" selection-end-line="11" selection-end-column="21" />
|
||||
<folding>
|
||||
<element signature="e#310#311#0" expanded="true" />
|
||||
<element signature="e#362#363#0" expanded="true" />
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/tests/TestLights.java">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/FITBITUrl.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="8" column="17" selection-start-line="8" selection-start-column="17" selection-end-line="8" selection-end-column="17" />
|
||||
<state relative-caret-position="323">
|
||||
<caret line="19" column="5" lean-forward="true" selection-start-line="19" selection-start-column="5" selection-end-line="19" selection-end-column="5" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#225#226#0" expanded="true" />
|
||||
<element signature="e#258#259#0" expanded="true" />
|
||||
<element signature="e#333#334#0" expanded="true" />
|
||||
<element signature="e#362#363#0" expanded="true" />
|
||||
<element signature="e#461#462#0" expanded="true" />
|
||||
<element signature="e#497#498#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/AuthFITBIT.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state>
|
||||
<caret column="15" lean-forward="true" selection-start-column="15" selection-end-column="15" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/manage/UserData.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="255">
|
||||
<caret line="15" column="54" selection-start-line="15" selection-start-column="54" selection-end-line="15" selection-end-column="54" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
||||
@@ -18,5 +18,8 @@ dependencies {
|
||||
compile "com.google.code.gson:gson:2.8.0"
|
||||
// compile "org.xerial:sqlite-jdbc:3.15.1"
|
||||
compile 'org.apache.httpcomponents:httpclient:4.5.3'
|
||||
compile 'com.google.api-client:google-api-client:1.23.0'
|
||||
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta'
|
||||
|
||||
|
||||
}
|
||||
|
||||
116
src/main/java/manage/AuthFITBIT.java
Normal file
116
src/main/java/manage/AuthFITBIT.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package manage;
|
||||
|
||||
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;
|
||||
import com.google.api.client.auth.oauth2.BearerToken;
|
||||
import com.google.api.client.auth.oauth2.ClientParametersAuthentication;
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestFactory;
|
||||
import com.google.api.client.http.HttpRequestInitializer;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.JsonObjectParser;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.store.DataStoreFactory;
|
||||
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AuthFITBIT {
|
||||
|
||||
/** Directory to store user credentials. */
|
||||
private static final java.io.File DATA_STORE_DIR =
|
||||
new java.io.File(System.getProperty("user.home"), ".store/dailymotion_sample");
|
||||
|
||||
/**
|
||||
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
|
||||
* globally shared instance across your application.
|
||||
*/
|
||||
private static FileDataStoreFactory DATA_STORE_FACTORY;
|
||||
|
||||
/** OAuth 2 scope. */
|
||||
private static final String SCOPE = "read";
|
||||
|
||||
/** Global instance of the HTTP transport. */
|
||||
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
||||
|
||||
/** Global instance of the JSON factory. */
|
||||
static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
||||
|
||||
private static final String TOKEN_SERVER_URL = " https://api.fitbit.com/oauth2/token";
|
||||
private static final String AUTHORIZATION_SERVER_URL =
|
||||
"https://api.fitbit.com/oauth2/authorize";
|
||||
|
||||
/** Authorizes the installed application to access user's protected data. */
|
||||
private static Credential authorize() throws Exception {
|
||||
OAuth2ClientCredentials.errorIfNotSpecified();
|
||||
// set up authorization code flow
|
||||
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(BearerToken
|
||||
.authorizationHeaderAccessMethod(),
|
||||
HTTP_TRANSPORT,
|
||||
JSON_FACTORY,
|
||||
new GenericUrl(TOKEN_SERVER_URL),
|
||||
new ClientParametersAuthentication(
|
||||
OAuth2ClientCredentials.API_KEY, OAuth2ClientCredentials.API_SECRET),
|
||||
OAuth2ClientCredentials.API_KEY,
|
||||
AUTHORIZATION_SERVER_URL).setScopes(Arrays.asList(SCOPE))
|
||||
.setDataStoreFactory(DATA_STORE_FACTORY).build();
|
||||
// authorize
|
||||
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost(
|
||||
OAuth2ClientCredentials.DOMAIN).setPort(OAuth2ClientCredentials.PORT).build();
|
||||
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
|
||||
}
|
||||
|
||||
private static void run(HttpRequestFactory requestFactory) throws IOException {
|
||||
FITBITUrl url = new FITBITUrl("https://api.fitbit.com/1/user/-/profile.json"); //modificare con token?
|
||||
url.setFields("activity,heartrate,location,sleep");
|
||||
|
||||
HttpRequest request = requestFactory.buildGetRequest(url);
|
||||
UserData data = request.execute().parseAs(UserData.class);
|
||||
if (data.list.isEmpty()) {
|
||||
System.out.println("Error in retrieve user data");
|
||||
} /*else {
|
||||
if (data.hasMore) {
|
||||
System.out.print("First ");
|
||||
}*/ //i don't think is necessary
|
||||
/* System.out.println(data.list.size() + " favorite videos found:");
|
||||
for (Data datas: data.list) {
|
||||
System.out.println();
|
||||
System.out.println("-----------------------------------------------");
|
||||
System.out.println("ID: " + datas.id);
|
||||
System.out.println("Title: " + datas.title);
|
||||
System.out.println("Tags: " + datas.tags);
|
||||
System.out.println("URL: " + datas.url);
|
||||
}
|
||||
}*/ //neither this
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
|
||||
final Credential credential = authorize();
|
||||
HttpRequestFactory requestFactory =
|
||||
HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
|
||||
@Override
|
||||
public void initialize(HttpRequest request) throws IOException {
|
||||
credential.initialize(request);
|
||||
request.setParser(new JsonObjectParser(JSON_FACTORY));
|
||||
}
|
||||
});
|
||||
run(requestFactory);
|
||||
// Success!
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
22
src/main/java/manage/Data.java
Normal file
22
src/main/java/manage/Data.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package manage;
|
||||
|
||||
import com.google.api.client.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//da modificare inserendo gli attributi del json (activity, heartrate, sleep, location)
|
||||
|
||||
public class Data {
|
||||
|
||||
@Key
|
||||
public String id;
|
||||
|
||||
@Key
|
||||
public List<String> tags;
|
||||
|
||||
@Key
|
||||
public String title;
|
||||
|
||||
@Key
|
||||
public String url;
|
||||
}
|
||||
28
src/main/java/manage/FITBITUrl.java
Normal file
28
src/main/java/manage/FITBITUrl.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package manage;
|
||||
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.util.Key;
|
||||
|
||||
public class FITBITUrl extends GenericUrl {
|
||||
|
||||
@Key
|
||||
private String fields;
|
||||
|
||||
public FITBITUrl(String encodedUrl) {
|
||||
super(encodedUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fields
|
||||
*/
|
||||
public String getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fields the fields to set
|
||||
*/
|
||||
public void setFields(String fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
}
|
||||
26
src/main/java/manage/OAuth2ClientCredentials.java
Normal file
26
src/main/java/manage/OAuth2ClientCredentials.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package manage;
|
||||
|
||||
public class OAuth2ClientCredentials {
|
||||
|
||||
/** Value of the "API Key". */
|
||||
public static final String API_KEY = "22CSTL";
|
||||
|
||||
/** Value of the "API Secret". */
|
||||
public static final String API_SECRET = "ea2452013abd35609940ce5601960a08";
|
||||
|
||||
/** Port in the "Callback URL". */
|
||||
public static final int PORT = 8080;
|
||||
|
||||
/** Domain name in the "Callback URL". */
|
||||
public static final String DOMAIN = "http://127.0.0.1:8080/";
|
||||
|
||||
public static void errorIfNotSpecified() {
|
||||
if (API_KEY.startsWith("Enter ") || API_SECRET.startsWith("Enter ")) {
|
||||
System.out.println(
|
||||
"Enter API Key and API Secret from http://www.dailymotion.com/profile/developer"
|
||||
+ " into API_KEY and API_SECRET in " + OAuth2ClientCredentials.class);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
src/main/java/manage/UserData.java
Normal file
17
src/main/java/manage/UserData.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package manage;
|
||||
|
||||
|
||||
import com.google.api.client.util.Key;
|
||||
import java.util.List;
|
||||
|
||||
public class UserData {
|
||||
|
||||
@Key
|
||||
public List<Data> list;
|
||||
/*
|
||||
@Key
|
||||
public int limit;
|
||||
|
||||
@Key("has more")
|
||||
public boolean hasMore;*/ //don't think are needed
|
||||
}
|
||||
Reference in New Issue
Block a user