simonbromberg / googlefitbit Goto Github PK
View Code? Open in Web Editor NEWGoogle Sheets scripts for Fitbit data download (not actively maintained, feel free to submit a PR tho)
Google Sheets scripts for Fitbit data download (not actively maintained, feel free to submit a PR tho)
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 옵션을 사용하세요.)
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.
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.
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
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!
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
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",];
As a heads up to others, "Project Key" is deprecated. Use "Script ID" instead.
This can be found from the "Script Editor" GUI > File > Project Properties and must be used instead of the "Project Key" in the callback url (https://script.google.com/macros/d/YOUR_PROJECT_KEY/usercallback) otherwise you'll get a Invalid redirect_uri parameter value
error.
Would submit a pull request but it appears this project is no longer being maintained.
Hi,
Just wondering if you plan to add sleep data to intraday_all?
Thanks
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.
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:
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
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
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.
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
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?
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:
var userProperties = PropertiesService.getUserProperties();
as the first line of the functionScriptProperties.setProperty
with userProperties.setProperty
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.
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
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
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
It seems the structure of activities have changed .. as well as sleep structure (new Version 1.2) ...
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
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!
Particular values are successfully pulled (e.g., steps, distance) but other values give the following errors: "Error downloading sleep/timeInBed" and for many other variables.
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.
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
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.
I am able to download data with interday.gs. When I setup and then run the heartrate.gs I get the above error. Any ideas?
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."
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.