benjcunningham / googlecalendar

Easily access and modify calendars, events, and UI settings via the Google Calendar API
Other
12 stars 6 forks source link

Obscure error when running gc_auth #20

Open LiNk-NY opened 4 years ago

LiNk-NY commented 4 years ago

@benjcunningham

I am not sure if I'm providing the right credentials and the instructions are not very clear. I am getting an error when I added my googlecalendar.client_key and googlecalendar.client_secret in my ~/.Rprofile file. I must be missing something... Did you mean client_id and client_secret as shown here? https://weblizar.com/blog/get-google-calendar-client-id-and-client-secret-key/ If so, I've tried that and it doesn't work. I've also tried using my API Key 1 as the googlecalendar.client_key value and the client secret but to no success.

It would be good to have a template / description of what these keys look like or a step-by-step on how to obtain them as above.

Thanks, Marcel

library(googlecalendar)
tryCatch(gc_auth(new_user = TRUE), error = function(e) {
    conditionMessage(e)
})
#> [1] "cache should be length 1 vector"
sessionInfo()
#> R Under development (unstable) (2019-10-07 r77258)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 19.04
#> 
#> Matrix products: default
#> BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] googlecalendar_0.0.0.9000 nvimcom_0.9-70           
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.3       crayon_1.3.4     assertthat_0.2.1 digest_0.6.23   
#>  [5] dplyr_0.8.4      R6_2.4.1         magrittr_1.5     evaluate_0.14   
#>  [9] httr_1.4.1       pillar_1.4.3     highr_0.8        rlang_0.4.4     
#> [13] stringi_1.4.5    rmarkdown_2.1    tools_4.0.0      stringr_1.4.0   
#> [17] glue_1.3.1       purrr_0.3.3      xfun_0.12        yaml_2.2.1      
#> [21] compiler_4.0.0   pkgconfig_2.0.3  htmltools_0.4.0  tidyselect_1.0.0
#> [25] knitr_1.27       tibble_2.1.3

Created on 2020-02-07 by the reprex package (v0.3.0)

Karnner2 commented 4 years ago

gc_auth(new_user = TRUE, cache =TRUE ),

if you pull the help log you will see that this is a third set-able option in the .Rprofile as well.

LiNk-NY commented 4 years ago

Thanks @Karnner2 for resolving the error. The cache=TRUE would be helpful to have in the README.md.

@benjcunningham I am still having authentication issues given that the documentation isn't very clear.

Does the client_key correspond to the API key that we generate here? Does the client_secret correspond to the 'Client secret' under OAuth 2.0 Client IDs? Where does Client ID under OAuth 2.0 Client IDs fit into all of this?

These are the options: Screenshot from 2020-08-17 14-34-09

This is my setup: Screenshot from 2020-08-17 14-38-06

Your help is appreciated. Thanks!

Karnner2 commented 4 years ago

@LiNk-NY , I know you asked @benjcunningham but the following works for me.

gc_auth(new_user=TRUE, key= ' your API key', secret = 'API secret/passcode', token = NULL, cache=TRUE)

With respect to where the key generation occurs, yes, those should work. It appears that the code is just dated (possibly) and the Oath2.0 terminology has replaced the prior terminology that @benjcunningham used. It still works. You only need the client ID if you are going to be editing someone else's calendar through the API, but if I recall you need your app approved by Google in order to do this. The new_user=TRUE parameter will activate a browser which will give your computer a token for your session. You only need to do it the one time so long as the session ID is good.

LiNk-NY commented 4 years ago

No, thanks for helping Jonathan! @Karnner2

For some reason, calling gc_auth without .Rprofile settings works.

I used the key = <Client ID> and secret = <Client secret> from the Google Developer's Console otherwise it would give me an error if I tried to use a generated key = <API key>:

Authorization Error
Error 401: invalid_client
The OAuth client was not found.

After authenticating successfully(?), I ran gc_ls() and got an error:

gc_ls()
Error: C stack usage  7971948 is too close to the limit
In addition: Warning messages:
1: `tbl_df()` is deprecated as of dplyr 1.0.0.
Please use `tibble::as_tibble()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 
2: `funs_()` is deprecated as of dplyr 0.7.0.
Please use `funs()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 
3: `funs()` is deprecated as of dplyr 0.8.0.
Please use a list of either functions or lambdas: 

  # Simple named list: 
  list(mean = mean, median = median)

  # Auto named with `tibble::lst()`: 
  tibble::lst(mean, median)

  # Using lambdas
  list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 
4: `mutate_each_()` is deprecated as of dplyr 0.7.0.
Please use `across()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 

It seems like there is a recursive call somewhere. I haven't looked into it. :disappointed:

Karnner2 commented 4 years ago

@LiNk-NY, you can ignore the errors for now. Although they are depreciated it should not actually matter for the time being. Be-careful with what you are getting though, the function gc_ls() returns a list not a df or vector. So within the list result you need to call the specific list element (i.e. 'summary'), try the following:

result<-gc_ls(pattern="") result$summary

Also yes, there is no actual need to set up a .Rprofile when accessing an API, you can always call directly through the client function. The .Rprofile is just a 'hide my information' method so that you don't accidentally commit to github your API Key and Secret (or other userID and password set). Having actually done this on accident, I can attest to its usefulness in that way. 😁

After you have identified the calendar you want to manipulate using gc_ls() (for example, I use this API to automatically post meals to my calendar by merging with Spoonacular API so I will provide some 'methods' in that framework,) do

Eating<-gc_summary("Eating Schedule") where Eating Schedule is the name of my calendar found from gc_ls; you post a new event with the following type of call:

gc_event_new(Eating, start=list("T11:00:00Z"), end=list("T12:00:00Z), summary="Event Title", description="Event Details")

the Event Title is what would show up in your main event on your gCalendar, this is usually a recipe name for me in this framework so let's say 'Thai Shrimp Soup'. The 'Event Details' contains all the information that is additional such as location, and notes about what the meeting is for etc. I was intuitive that since google runs HTML5 you can push HTML markup through this as a string and google will render it appropriately.

So you can pass headers (<h2>) and breaks (<br>) plus list mark-ups, etc. in HTML and google handles it flawlessly. Here is an example of what this looks like. I simply make a loop with strings, times and dates using the bizdays, lubridate, and bsts libraries.

Capture

LiNk-NY commented 4 years ago

@Karnner2 I see, it seems like the show/print method is broken :grimacing:

Thanks for all the help! I am able to see my events now.

Cool example! It almost looks like a breakfast recipe for shakshuka :wink: I wonder if you can render an RMD to HTML for the calendar. It might be overkill but at least I've got things working now! Thanks again!

All the best, Marcel

BertaBojte commented 4 years ago

I have a problem with auth as well, although it seems different. Whenever I would like to connect to the calendar through the package and the API, it fails. The Authentication seems successful, but then if I want to list out the available calendars (or load a calendar by ID, or anything else), I get an error. My code is the following: gc_auth( new_user = T, key = CLIENT_ID, secret = CLIENT_SECRET, verbose = T, token = NULL, cache = T ) After this, I get the browser popping up, I allow the app to connect, and returning to R I see the message: Authentication complete.

So after this I run gc_ls(), but get the following error: Error in function_list[[k]](value) : Bad Request (HTTP 400).

I've tried many formats for gc_ls, also tried with different Google application (OAuth clients), and always get the same result.

Does anyone have a suggestion for this?

Thanks, Berta

LiNk-NY commented 4 years ago

Hi Berta! @BertaBojte

It seems like you were able to authenticate okay.

You then have to do something like:

res <- gc_ls(pattern = "")
res$summary

Best, Marcel

abjeroen commented 3 years ago

I'm on the same page as Berta. res <- gc_ls(pattern = "") res$summary Gives me `res <- gc_ls(pattern = "") Error in httr::GET(url, gc_token()) %>% httr::stop_for_status() : Forbidden (HTTP 403).

res$summary Error: object 'res' not found

`

LiNk-NY commented 3 years ago

Hi @abjeroen

Make sure the authentication is complete after you get the browser pop-up.

Best, Marcel

LiNk-NY commented 2 years ago

@abjeroen It looks like build_url appends the key parameter in the URL. This is not needed. I have a fork at https://github.com/LiNk-NY/googlecalendar that should fix this.

oscarepaezm commented 1 year ago

I am with the same Errror as @BertaBojte
After "Authentication complete."

I try to use gc_ls(pattern = "") and give me the Error: Error in httr::GET(url, gc_token()) %>% httr::stop_for_status() : Bad Request (HTTP 400).

How can I fix this?

Thanks Oscar

Karnner2 commented 1 year ago

Try gc_ls(pattern=“”) or, if google’s backend is using regex you may need to go that route, gc_ls(“.”)

Right now you are asking it to find “string null” and that might be the bad request.

On Thu, Dec 29, 2022 at 4:23 AM oscarepaezm @.***> wrote:

I am with the same Errror as @BertaBojte https://github.com/BertaBojte After "Authentication complete."

I try to use gc_ls(pattern = "") and give me the Error: Error in httr::GET(url, gc_token()) %>% httr::stop_for_status() : Bad Request (HTTP 400).

How can I fix this?

Thanks Oscar

— Reply to this email directly, view it on GitHub https://github.com/benjcunningham/googlecalendar/issues/20#issuecomment-1367182433, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHTXJHBMQQMIS2NUC4TVF3WPVJ77ANCNFSM4KRUW3BQ . You are receiving this because you were mentioned.Message ID: @.***>

Karnner2 commented 1 year ago

I also see Marcel has forked the correction. While I haven’t examined either the original main branch source or Marcel’s fork, based on the description—the gc_ls uses build_url and that build_url at one point required the API key to be in it for the API’s server to accept the request.

Google may have updated their end-point and so you will need to update as well. So try using Marcel’s fork and or what I referred to and see if that doesn’t fix your problem. Let us know if not.

On Thu, Dec 29, 2022 at 9:26 AM Jonathan Fluharty @.***> wrote:

Try gc_ls(pattern=“”) or, if google’s backend is using regex you may need to go that route, gc_ls(“.”)

Right now you are asking it to find “string null” and that might be the bad request.

On Thu, Dec 29, 2022 at 4:23 AM oscarepaezm @.***> wrote:

I am with the same Errror as @BertaBojte https://github.com/BertaBojte After "Authentication complete."

I try to use gc_ls(pattern = "") and give me the Error: Error in httr::GET(url, gc_token()) %>% httr::stop_for_status() : Bad Request (HTTP 400).

How can I fix this?

Thanks Oscar

— Reply to this email directly, view it on GitHub https://github.com/benjcunningham/googlecalendar/issues/20#issuecomment-1367182433, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHTXJHBMQQMIS2NUC4TVF3WPVJ77ANCNFSM4KRUW3BQ . You are receiving this because you were mentioned.Message ID: @.***>

oscarepaezm commented 1 year ago

Try gc_ls(pattern=“”) or, if google’s backend is using regex you may need to go that route, gc_ls(“.”) Right now you are asking it to find “string null” and that might be the bad request. On Thu, Dec 29, 2022 at 4:23 AM oscarepaezm @.> wrote: I am with the same Errror as @BertaBojte https://github.com/BertaBojte After "Authentication complete." I try to use gc_ls(pattern = "") and give me the Error: Error in httr::GET(url, gc_token()) %>% httr::stop_for_status() : Bad Request (HTTP 400). How can I fix this? Thanks Oscar — Reply to this email directly, view it on GitHub <#20 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHTXJHBMQQMIS2NUC4TVF3WPVJ77ANCNFSM4KRUW3BQ . You are receiving this because you were mentioned.Message ID: @.>

Now with gc_ls(pattern="*") the the function is working !!!

Thanks so much!