GithubHelp home page GithubHelp logo

simonbromberg / googlefitbit Goto Github PK

View Code? Open in Web Editor NEW
165.0 165.0 49.0 69 KB

Google Sheets scripts for Fitbit data download (not actively maintained, feel free to submit a PR tho)

JavaScript 100.00%

googlefitbit's People

Contributors

dsoim avatar erramirez avatar iziki avatar simonbromberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

googlefitbit's Issues

Code 401 error

When sync ended, this error occurs.(interday)

https://api.fitbit.com/1/user/-/profile.json에 대한 요청이 실패하여 코드 401이(가) 반환되었습니다(Request failed. Code 401 returned). 서버 응답이 잘림: {"errors":[{"errorType":"authorization","fieldName":"authorization","message":"This application does not have permission to access profile data."}]...(전체 응답을 확인하려면 muteHttpExceptions 옵션을 사용하세요.)

Heartrate.gs OAuth2 Reference Error

When running the Heartrate.gs in Google Script Editor, I get a ReferenceError: "OAuth2" is not defined when running the Authorize/Download Data Fitbit function.

Under the script editor, I get this error message:

error message

Any help would be greatly appreciated!!!

Thanks,
Jim

Error: Access not granted or expired

I've followed the instructions in Interday.gs without any issues, however when syncing at the end of the instructions, the error in Google spreadsheets comes up in a red box: "Error: Access not granted or expired. Details Dismiss".
Clicking 'Details' returns the message box "Error: Access not granted or expired.".
Clicking on the 'Fitbit' Menu and 'Authorize' brings up a side box on the right with a link which leads to 'fitbit.com/oauth2/authorize?client_id=....' with the following error message:
"The app you're trying to connect did not provide valid information to Fitbit. Please report this issue to them.

Developer information: invalid_request - Invalid redirect_uri parameter value "
I have the latest library resource 'OAuth2' available which is currently at version 26.

UiApp has been deprecated

When attempting to run the script for a new spreadsheet (or change settings in existing spreadsheet) the following message is now displayed.

"UiApp has been deprecated. Please use HtmlService instead."

Occurs when going to Fitbit menu item and selecting Setup menu choice.

intraday_all.gs: "dataset" from undefined

Hi,

I was following lilmo feedback on the intraday_all.gs but I am getting the following error:

[17-11-12 00:57:15:127 GMT] Sheet.getRange([a1]) [0.058 seconds]
[17-11-12 00:57:15:171 GMT] Range.setValue([Time]) [0.044 seconds]
[17-11-12 00:57:15:427 GMT] UrlFetchApp.fetch([https://api.fitbit.com/1/user/-/activities/steps/date/2017-11-11/1d.json, {headers={Authorization=Bearer eyJhbGcuednmkwejd92309.eyJzdWIiOiI2kldwjdo3iNLRlgiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3Nf, =}}]...) [0.254 seconds]
[17-11-12 00:57:15:428 GMT] HTTPResponse.getContentText() [0 seconds]
[17-11-12 00:57:15:429 GMT] Range.offset([0, 1]) [0 seconds]
[17-11-12 00:57:15:430 GMT] Range.setValue([steps]) [0.001 seconds]
[17-11-12 00:57:15:495 GMT] Execution failed: TypeError: Cannot read property "dataset" from undefined. (line 332, file "Code") [0.696 seconds total runtime]

The interday.gs works fine.

Many Thanks,
Eugen

intraday_all for yesterday

Hi!
First of all, THANK YOU very much for publishing these scripts, I wouldn't have been able to create them myself :)

I created a script to generate a new Google spreadsheet everyday with the data provided by intraday_all.gs. For it to work, I would need the intraday_all script to fetch yesterday's data, not today's (else I would have to run my script at exactly 11:59pm every day, and google triggers don't allow to be that precise). I couldn't find what I should change in the code to override the "today" from the setup form.
Any help would be greatly appreciated.
Thanks!

intraday HR for multiple days

Hi
great code - thanks a lot - runs very smoothly.
Would i be possible to get a function to retrieve intraday HR over a period of time when you have some time?
That would be most useful.
Thanks

Additional information regarding Sync errors on some Fitbit data

These are the Loggables that are having issues:
foods/log/claoriesIn
sleep/timeInBed
sleep/minutesAsleep
sleep/minutesAwake
sleep/awakeningsCount
body/weight
body/bmi
body/fat

I noticed that all the Loggables with activities/log work and foods,sleep and body do not. Sorry I am not experienced enough to figure out why and how to fix the Logger.log function or maybe a better way to define the var. So I edited the var LOGGABLES section to remove those that are not working , add floors and put the activities in the order you would see them if you did a direct download from Fitbit.

// Default loggable resources (from Fitbit API docs).
var LOGGABLES = ["activities/log/calories", "activities/log/steps", "activities/log/distance","activities/log/floors","activities/log/minutesSedentary","activities/log/minutesLightlyActive","activities/log/minutesFairlyActive","activities/log/minutesVeryActive","activities/log/activityCalories",];

New V8 runtime Error and Data Download Error with workarounds (from a newb)

I have very limited coding experience, and recently went to use the original code by @simonbromberg. I ran into 3 issues that were not addressed in the initial setup instructions, last updated in 2018. I thought I would put them here for other newbs who are just trying to get their Fitbit data.

The first issue is that Google's script editor has been switched over to V8 runtime; which seems to have happened around Feb 2020. This meant that I needed to use the latest version (38) of the OAuth2.0 library, not version 19 as was mentioned.

I needed to tweak the First Date in the gs script to get the data. I had to set the 'getFirstDate' function to the day I was pulling info from. It is defaulted to 01/01/2012 and would not save as any other date for me. I just changed the date in the gs code to be the current date and was able to pull this info when I went to Download Data later.

The remaining issues I ran into have already been addressed in @lordneeko's post and @rubenflamshepherd's post.


The second issue was that the UI has been deprecated. This was well addressed by @lordneeko in his PR#37 post. You just use the Setup.html code and save it as Setup in the script editor and then use the respective gs codes he has listed (intraday.gs, heartrate.gs, etc.) as you would have previously. @pjfarr explained how to do this well in his reply on @lordneeko 's post.

The final issue was that the Project Key for the callback URL did not work for me and I instead used the script ID setup discussed in this post by Jozef Jarosciak and by @rubenflamshepherd's post.


I have only used the heartrate.gs file so far, and it worked. Adjusting for these 3 issues and the date seemed to do the trick. Jozef Jarosciak's instructions were very helpful for someone lacking experience.

**I don't know a lot of the jargon, so I apologize if some of my terminology was off.

TypeError on FitBit>Download Data

First, I'm assuming Step 7 should say "Download Data" instead of "Sync", please correct me if I'm wrong.

After following steps 1-6 under "Setting Up" for interday.gs, I attempted step 7 and received the following error in a red box at the top of the spreadsheet:
TypeError: Cannot call method "getContentText" of undefined.

I can see that the following changes were made to the spreadsheet when clicking Download Data, even though there was an error:

  1. Cell A1 is populated with my name and a note with my date of birth.
  2. Cell A2 is populated with "undefined/undefined/undefined"
  3. Rows 1 and 2 were "frozen".

Do you have any suggestions? Is it possible that some new steps are required due to possible changes on FitBit's end?

Also, when I go to the script editor and click Run>setup and then click the red lightbulb labeled "Execution Hints", I get a yellow popup with the text below. I'm not sure if this is a FitBit-specific issue?

UiApp API is deprecated.
File: Code Line: 134
FlowPanel API is deprecated.
File: Code Line: 187
Grid API is deprecated.
File: Code Line: 170
Button API is deprecated.
File: Code Line: 190
ScriptProperties API is deprecated.
File: Code Line: 47
Label API is deprecated.
File: Code Line: 190
ServerHandler API is deprecated.
File: Code Line: 184
UiInstance API is deprecated.
File: Code Line: 134
TextBox API is deprecated.
File: Code Line: 139

Intraday_all does not Work

By downloading the data, I do get the Error : "Method "getmaxRows" from zero can not be run.
Can anyone help on this?

var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheet = doc.getSheetByName(mySheetName);
var lastrow = sheet.getMaxRows();
sheet.clear();
if (lastrow > 3) { sheet.deleteRows(2, lastrow -2); }
sheet.setFrozenRows(1);

Thank you

invalid_request - Invalid redirect_uri parameter value

Hey guys, I'm getting this error on Step 6 when I try to authorize the app:

The app you're trying to connect did not provide valid information to Fitbit. Please report this issue to them.

Developer information: invalid_request - Invalid redirect_uri parameter value

I was able to bypass this error by selecting OAuth2 version 19 (instead of selecting the latest version) in the resources library in the scripts.

Error

Hi Simon,
Thanks for the script. On the very last stage when I try to authorize I get the following error:

Error retrieving token: 401 (line 305, file "Service", project "OAuth2")

What should I try to do?

Many thanks,
Kishan

This app cannot be verified

In step 2 after downloading OAuth2 library newest version #32 1.32.0, selecting fitbit setup it runs the script but needs permission to do so. I continue to select my gmail account and it responds "This app isn't verified". In addition in the script editor I select file and then project properties and the project key "MVEEoz0tJovApU8EsAUDRv2GcTaOpszs" is (Deprecated). How do you get auhorization for the app?

ScriptProperties is deprecated

Hi Simon

I opened an issue a little bit ago which I thought was resolved by using the correct script. However, I found that the interday script uses ScriptProperties, which is deprecated and not working. I modified the script to use PropertiesService - I'm have a somewhat limited understanding of coding, but I modified each function which included "ScriptProperties.setProperty" or "ScriptProperties.getProperty" by doing the following:

  1. Add var userProperties = PropertiesService.getUserProperties(); as the first line of the function
  2. Replace all instances of ScriptProperties.setProperty with userProperties.setProperty
  3. Replace all instances of ScriptProperties.getProperty with userProperties.getProperty

I think that adding var userProperties = PropertiesService.getUserProperties(); anywhere before line 44 would have also worked instead of adding it as the first line of any function using ScriptProperties, but I didn't test this.

TypeError: Cannot call method "getContentText" of undefined.

Hi,
I have done the same that you mentioned in the readme when i hit sync i am getting this error .
Can you please help me out on this ?

TypeError: Cannot call method "getContentText" of undefined.

Sheet last synced: Thu Sep 17 2015 16:44:13 GMT-0700 (PDT)
Battery
Last Sync
Date

Problems with access and data loading

Dear Simon,
I am a psychiatrist with only very small knowledge in programming. For a study I want to get the intraday sleep data out of the Fitbit One. I requested a partner API as recommend and got access. I was very lucky to find your intraday.gs, but after several days of trying and getting forward slowly, I now hit a wall, I cannot go through on my own due to my lack of knowledge at these things. I would really appreciate your help.
My problem start and step 6:

In your spreadsheet, click Authorize from the Fitbit menu and a sidebar will show up. Click the link in the >sidebar, log in to Fitbit in the new window, authorize the application, and then close the tab when it says >"Success you can close this tab"

I do not find a authorize command, but I clicked the showSidebar, then I can authorize. In the new window Fitbit asks me to accept or deny the ability to access the certain data in my account. However, when I click accept, the message "Success you can close this tab" does not appear, but a blank page. When I then go to step 7:

Back in your spreadhseet, hit Sync, and after a few moments the data should load in.
There is no Sync command but a refreshTimeSeries command. However when I click it, a message appears saying: "Access not granted or expired". I thought the Fitbit API team provided access to me...

If you have an ideas to my problem I would really appreciate your input. Coffee is for sure ;-)

Best wishes,
Laura

Error downloading activities/log/steps

Setup my Google Spreadsheet, everything got authorized. Go to Sync under the Fitbit menu drop down, get a pop up with the error that says the following - "Error downloading activities/log/steps". That's all I get. No numbers, no codes. The screen shot is attached.

I am using interday.gs and I had to use the Script ID to authorize instead of the project key

snip_20170804085120

dataset from undefined

Hello,
I tried intraday and interday and they worked very weel but whenI run the intraday_all I got this message "TypeError: Unable to read dataset property from undefined" any idea ?
Thanks by advance

Can't get Intraday data

I have followed all the instructions and managed to get interday data to work. I'm trying to go through and apply the same steps to the intraday scripts - I've tired both. The issue I'm having is that I can't get the 'Sync' option to show up for the last steps. I have no idea where I'm going wrong but noticed on these script there is no mention of sync function.

Hope you can help, thanks!

Resting HR Could be added to interday.gs

Note I have no idea what I'm doing on github so there's probably a not terrible way to document this correctly. Sorry.

The way I did this might be a little hacky, but it's definitely possible without too much trouble. It might be worth adding this - I know I was very interested in having this included, in addition to the other columns already there.

  1. Add "activities/heart" to LOGGABLES
  2. Include heartrate in setscope
  3. Add conditional within sync data population to check title != "heart"
    If true -> cell.offset(index, !dateColDone + activity * 1.0).setValue(val["value"]); (no change)
    If false -> cell.offset(index, !dateColDone + activity * 1.0).setValue(val["value"]["restingHeartRate"]);

Data downloading error.

This errors occurs.

Error downloading foods/log/caloriesIn
Error downloading sleep/timeInBed
Error downloading sleep/minutesAsleep
Error downloading sleep/minutesAwake
Error downloading sleep/awakeningsCount
Error downloading body/weight
Error downloading body/bmi
Error downloading body/fat

and result is this.
2015-10-22 11 57 39

Redirect URI mismatch error when authorizing Fitbit application

A couple of users have pointed out this error after authorizing the Fitbit application.

Error retrieving token: 400: {"errors":[{"errorType":"invalid_request","message":"Redirect_uri mismatch: https://script.google.com/macros/d/YOUR_PROJECT_KEY/usercallback. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false,"granted_time":1465533824} (line 402, file "Service", project "OAuth2")

Looking into it. Anyone with insight please feel free to comment here.

Error on Authorization

Everything was working fine until today. Now I get this error when I use the sync option:
image

And when I try to authorize I get:
Data storage error (line 493, file "Service", project "OAuth2")

Any ideas?

State token invalid or expired

I'm going through the process of loading this code and everything goes as expected until I go to the authorize part. It goes to the fitbit page with 'heart rate', 'activity and exercise', and 'profile' where you can deny or allow. Upon clicking 'allow'. This error appears:
"The state token is invalid or has expired. Please try again."

script unable to download some data

The script is throwing up an error dialog for the following:

caloriesin
timeinbed
minutesasleep
minutesawake
awakeningscount
weight
bmi
fat

everytime it throws up an error about a specific metric, it duplicates the previous metric.

Sleep Stages Request

Hi everyone, not sure if this is the right place to put a feature request, so I'm just going to put it here in issues (feel free to delete this).
https://dev.fitbit.com/docs/sleep/#get-sleep-logs-list
Fitbit just pushed out new sleep stages information. Would it be possible to modify the code here to start pulling this new data in?
Thanks - nick

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.