Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ And "_Developer information: invalidrequest - Invalid redirecturi parameter valu

That means you did not follow the instructions correctly.

For all intraday scripts you must also get the Setup.html file. This file should be loaded to your google scripts project as well. The HtmlService will use this when calling the Setup function.

## interday.gs
Download step data, one row per day, from a start day to the present. Make sure not to set the start day too far in the past.

Expand Down
82 changes: 82 additions & 0 deletions Setup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type=submit]:hover {
background-color: #45a049;
}

div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 10px;
}
</style>
<head>

</head>
<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<div>
Fitbit OAuth 2.0 Client ID:*
<input type="text" name="consumerKey" style="width:100%"/>
</div>
<div>
Fitbit OAuth Consumer Secret:*
<input type="text" name="consumerSecret" style="width:100%"/>
</div>
<div>
Project Key:
<input type="text" name="projectKey" style="width:100%;color:grey" readonly/>
</div>
<div>
First Date:
<input type="date" name="firstDate" style="width:100%"/>
</div>
<input type="submit" value="Save"/>
</form>
<div id="output"></div>
<script>
function handleFormSubmit(formObject) {
google.script.run.saveSetup(formObject);
google.script.host.close();
}
function onSuccessKey(key) {
document.getElementsByName("consumerKey")[0].value = key;
}
function onSuccessSecret(secret) {
document.getElementsByName("consumerSecret")[0].value = secret;
}
function onSuccessProject(project) {
document.getElementsByName("projectKey")[0].value = project;
}
function onSuccessDate(date) {
document.getElementsByName("firstDate")[0].value = date;
}
var key = google.script.run.withSuccessHandler(onSuccessKey).getConsumerKey();
var secret = google.script.run.withSuccessHandler(onSuccessSecret).getConsumerSecret();
var projectKey = google.script.run.withSuccessHandler(onSuccessProject).getProjectKey();
var firstDate = google.script.run.withSuccessHandler(onSuccessDate).getFirstDate();
</script>
</body>
</html>
104 changes: 23 additions & 81 deletions heartrate.gs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@ var GET_HEART_RATE_DATA = 1; // set this to 0 if you want to do step data instea


function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{
name: "Setup",
functionName: "setup"
},
{
name: "Authorize",
functionName: "showSidebar"
},
{
name: "Reset",
functionName: "clearService"
},
{
name: "Sync",
functionName: "refreshTimeSeries"
}];
ss.addMenu("Fitbit", menuEntries);

SpreadsheetApp.getUi()
.createMenu("Intraday Fitbit HeartRate")
.addItem('Setup','setup')
.addItem('Authorize', 'showSidebar')
.addItem('Reset', 'clearService')
.addItem("Download data", 'refreshTimeSeries')
.addToUi();

}


Expand Down Expand Up @@ -78,16 +68,18 @@ function getConsumerSecret() {
return secret;
}

function getProjectKey() {
return ScriptApp.getProjectKey();
}

// function saveSetup saves the setup params from the UI
function saveSetup(e) {
setConsumerKey(e.parameter.consumerKey);
setConsumerSecret(e.parameter.consumerSecret);
setLoggables(e.parameter.loggables);
setFirstDate(e.parameter.firstDate);
setLastDate(e.parameter.lastDate);
var app = UiApp.getActiveApplication();
app.close();
return app;

setConsumerKey(e.consumerKey);
setConsumerSecret(e.consumerSecret);
setLoggables(e.loggables);
setFirstDate(e.firstDate);

}

function setFirstDate(firstDate) {
Expand Down Expand Up @@ -117,61 +109,11 @@ function getLastDate() {

// function setup accepts and stores the Consumer Key, Consumer Secret, Project Key, firstDate, and list of Data Elements
function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle("Setup Fitbit Download");
app.setStyleAttribute("padding", "10px");

var consumerKeyLabel = app.createLabel("Fitbit OAuth 2.0 Client ID:*");
var consumerKey = app.createTextBox();
consumerKey.setName("consumerKey");
consumerKey.setWidth("100%");
consumerKey.setText(getConsumerKey());

var consumerSecretLabel = app.createLabel("Fitbit OAuth Consumer Secret:*");
var consumerSecret = app.createTextBox();
consumerSecret.setName("consumerSecret");
consumerSecret.setWidth("100%");
consumerSecret.setText(getConsumerSecret());

var projectKeyTitleLabel = app.createLabel("Project key: ");
var projectKeyLabel = app.createLabel(ScriptApp.getProjectKey());

var firstDate = app.createTextBox().setId("firstDate").setName("firstDate");
firstDate.setName("firstDate");
firstDate.setWidth("100%");
firstDate.setText(getFirstDate());

var lastDate = app.createTextBox().setId("lastDate").setName("lastDate");
lastDate.setName("lastDate");
lastDate.setWidth("100%");
lastDate.setText(getLastDate());
// create the save handler and button
var saveHandler = app.createServerClickHandler("saveSetup");
var saveButton = app.createButton("Save Setup", saveHandler);

// put the controls in a grid
var listPanel = app.createGrid(8, 3);
listPanel.setWidget(1, 0, consumerKeyLabel);
listPanel.setWidget(1, 1, consumerKey);
listPanel.setWidget(2, 0, consumerSecretLabel);
listPanel.setWidget(2, 1, consumerSecret);
listPanel.setWidget(3, 0, app.createLabel(" * (obtain these at dev.fitbit.com, use OAuth2.0)"));
listPanel.setWidget(4, 0, projectKeyTitleLabel);
listPanel.setWidget(4, 1, projectKeyLabel);
listPanel.setWidget(5, 0, app.createLabel("Start Date for download (yyyy-mm-dd)"));
listPanel.setWidget(5, 1, firstDate);
listPanel.setWidget(6, 0, app.createLabel("End date for download (yyyy-mm-dd)"));
listPanel.setWidget(6, 1, lastDate);
listPanel.setWidget(7, 0, app.createLabel("Very long intervals will not work; exceed Fitbit rate limit and/or function will timeout"));

// Ensure that all controls in the grid are handled
saveHandler.addCallbackElement(listPanel);
// Build a FlowPanel, adding the grid and the save button
var dialogPanel = app.createFlowPanel();
dialogPanel.add(listPanel);
dialogPanel.add(saveButton);
app.add(dialogPanel);
doc.show(app);
var html = HtmlService.createHtmlOutputFromFile('Setup').setHeight(1200);

SpreadsheetApp.getUi()
.showModalDialog(html, 'Setup');
}

function getFitbitService() {
Expand Down
106 changes: 24 additions & 82 deletions intraday.gs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,17 @@ var CONSUMER_SECRET_PROPERTY_NAME = "fitbitConsumerSecret";
var SERVICE_IDENTIFIER = 'fitbit';

function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{
name: "Setup",
functionName: "setup"
},
{
name: "Authorize",
functionName: "showSidebar"
},
{
name: "Reset",
functionName: "clearService"
},
{
name: "Download data",
functionName: "refreshTimeSeries"
}];
ss.addMenu("Fitbit", menuEntries);

SpreadsheetApp.getUi()
.createMenu("Intraday Fitbit")
.addItem('Setup','setup')
.addItem('Authorize', 'showSidebar')
.addItem('Reset', 'clearService')
.addItem("Download data", 'refreshTimeSeries')
.addToUi();

}


function isConfigured() {
return getConsumerKey() != "" && getConsumerSecret() != "";
}
Expand Down Expand Up @@ -83,16 +72,19 @@ function getConsumerSecret() {
return secret;
}

function getProjectKey() {

return ScriptApp.getProjectKey();
}

// function saveSetup saves the setup params from the UI
function saveSetup(e) {
setConsumerKey(e.parameter.consumerKey);
setConsumerSecret(e.parameter.consumerSecret);
setLoggables(e.parameter.loggables);
setFirstDate(e.parameter.firstDate);
setLastDate(e.parameter.lastDate);
var app = UiApp.getActiveApplication();
app.close();
return app;

setConsumerKey(e.consumerKey);
setConsumerSecret(e.consumerSecret);
setLoggables(e.loggables);
setFirstDate(e.firstDate);

}

function setFirstDate(firstDate) {
Expand Down Expand Up @@ -122,61 +114,11 @@ function getLastDate() {

// function setup accepts and stores the Consumer Key, Consumer Secret, Project Key, firstDate, and list of Data Elements
function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle("Setup Fitbit Download");
app.setStyleAttribute("padding", "10px");

var consumerKeyLabel = app.createLabel("Fitbit OAuth 2.0 Client ID:*");
var consumerKey = app.createTextBox();
consumerKey.setName("consumerKey");
consumerKey.setWidth("100%");
consumerKey.setText(getConsumerKey());

var consumerSecretLabel = app.createLabel("Fitbit OAuth Consumer Secret:*");
var consumerSecret = app.createTextBox();
consumerSecret.setName("consumerSecret");
consumerSecret.setWidth("100%");
consumerSecret.setText(getConsumerSecret());

var projectKeyTitleLabel = app.createLabel("Project key: ");
var projectKeyLabel = app.createLabel(ScriptApp.getProjectKey());

var firstDate = app.createTextBox().setId("firstDate").setName("firstDate");
firstDate.setName("firstDate");
firstDate.setWidth("100%");
firstDate.setText(getFirstDate());

var lastDate = app.createTextBox().setId("lastDate").setName("lastDate");
lastDate.setName("lastDate");
lastDate.setWidth("100%");
lastDate.setText(getLastDate());
// create the save handler and button
var saveHandler = app.createServerClickHandler("saveSetup");
var saveButton = app.createButton("Save Setup", saveHandler);

// put the controls in a grid
var listPanel = app.createGrid(8, 3);
listPanel.setWidget(1, 0, consumerKeyLabel);
listPanel.setWidget(1, 1, consumerKey);
listPanel.setWidget(2, 0, consumerSecretLabel);
listPanel.setWidget(2, 1, consumerSecret);
listPanel.setWidget(3, 0, app.createLabel(" * (obtain these at dev.fitbit.com, use OAuth2.0)"));
listPanel.setWidget(4, 0, projectKeyTitleLabel);
listPanel.setWidget(4, 1, projectKeyLabel);
listPanel.setWidget(5, 0, app.createLabel("Start Date for download (yyyy-mm-dd)"));
listPanel.setWidget(5, 1, firstDate);
listPanel.setWidget(6, 0, app.createLabel("End date for download (yyyy-mm-dd)"));
listPanel.setWidget(6, 1, lastDate);
listPanel.setWidget(7, 0, app.createLabel("Very long intervals will not work; exceed Fitbit rate limit and/or function will timeout"));

// Ensure that all controls in the grid are handled
saveHandler.addCallbackElement(listPanel);
// Build a FlowPanel, adding the grid and the save button
var dialogPanel = app.createFlowPanel();
dialogPanel.add(listPanel);
dialogPanel.add(saveButton);
app.add(dialogPanel);
doc.show(app);
var html = HtmlService.createHtmlOutputFromFile('Setup').setHeight(1200);

SpreadsheetApp.getUi()
.showModalDialog(html, 'Setup');
}

function getFitbitService() {
Expand Down
Loading