mlampros / fitbitViz

Fitbit Visualizations
https://mlampros.github.io/fitbitViz/
9 stars 5 forks source link

Error: No automatic parser available for application/octet-stream. #1

Closed systemnova closed 3 years ago

systemnova commented 3 years ago

When i run: sleep_ts = fitbitViz::sleep_time_series(user_id = USER_ID, token = token, date_start = as.character(date_start), date_end = as.character(date_end), ggplot_color_palette = 'ggsci::blue_material', ggplot_ncol = 2, ggplot_nrow = 4, show_nchar_case_error = num_character_error, verbose = VERBOSE) sleep_ts$plt_lev_segments

I get back: Error: No automatic parser available for application/octet-stream.

Traceback reports

  1. stop("No automatic parser available for ", mt$complete, ".", call. = FALSE)

  2. parse_auto(raw, type, encoding, ...)
  3. httr::content(query_response, "parsed")
  4. sleep_single_day(user_id = user_id, token = token, date = seq_dates[idx], ggplot_color_palette = ggplot_color_palette, show_nchar_case_error = show_nchar_case_error, verbose = FALSE)
  5. fitbitViz::sleep_time_series(user_id = USER_ID, token = token, date_start = as.character(date_start), date_end = as.character(date_end), ggplot_color_palette = "ggsci::blue_material", ggplot_ncol = 2, ggplot_nrow = 4, show_nchar_case_error = num_character_error, ...
mlampros commented 3 years ago

hi @systemnova,

it seems the error comes from the httr::content() function. Can you please try the following and report back with the output. Make sure that you don't reveal your user_id and token (just double check before you copy-paste your output),


require(glue)
require(httr)

user_id = 'USE YOUR ID HERE'
token = 'USE YOUR TOKEN HERE'
date = 'USE A DATE THAT YOU UPLOADED DATA'            # such as '2021-05-01'

URL = glue::glue('https://api.fitbit.com/1.2/user/{user_id}/sleep/date/{date}/{date}.json')
auth_code = paste("Bearer", token)
query_response = httr::GET(url = URL, httr::add_headers(Authorization = auth_code))
query_response

This is my output of the query response variable,

Response [https://api.fitbit.com/1.2/user/XXXXXX/sleep/date/2021-05-01/2021-05-01.json]
Date: 2021-05-30 18:55
Status: 200
Content-Type: application/json;charset=UTF-8
Size: 3.66 kB

Normally you won't receive an error (status must be 200), therefore you can move to the next command,


content_list_obj = httr::content(query_response, "parsed")
str(content_list_obj)

my output of the previous command is

List of 1
$ sleep:List of 1
..$ :List of 15
.. ..$ dateOfSleep        : chr "2021-05-01"
.. ..$ duration           : int 23100000
.. ..$ efficiency         : int 97
.. ..$ endTime            : chr "2021-05-01T07:16:30.000"
.. ..$ infoCode           : int 0
.. ..$ isMainSleep        : logi TRUE
.. ..$ levels             :List of 3
.. .. ..$ data     :List of 28
.. .. .. ..$ :List of 3
.. .. .. .. ..$ dateTime: chr "2021-05-01T00:51:30.000"
.. .. .. .. ..$ level   : chr "wake"
.. .. .. .. ..$ seconds : int 30
.. .. .. ..$ :List of 3
.. .. .. .. ..$ dateTime: chr "2021-05-01T00:52:00.000"
.. .. .. .. ..$ level   : chr "light"
.. .. .. .. ..$ seconds : int 1590

Otherwise,

httr::content(query_response)

might give more details

mlampros commented 3 years ago

@systemnova I close the issue for now, feel free to re-open it.