Closed samfield closed 8 years ago
I think this is just a case that the default googleAuthR project isn't enabled with the Drive API. I can't turn on all the APIs else the consent screen would be enormous :)
You should be able to get it working setting up and creating your own Google Project and getting the client ID and secret, then putting them in the options googleAuthR.client_id
and googleAuthR.secret
before authentication. See the readme for more detail.
This is better in the long run anyhow as the API calls will run through that project, and not be affected by the global use of googleAuthR.
I got it to work with the default project by turning it on, but I'll turn it off again so you can try it yourself :) Here is working code:
#set scope and client id/secret
options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/drive")
options(googleAuthR.client_id = "CLIENT_ID_FROM_YOUR_PROJECT")
options(googleAuthR.client_secret = "CLIENT SECRET FROM YOUR PROJECT" )
#run the oauth flow
gar_auth()
#leads to: Authentication complete. Please close this page and return to R.
#construct API call
#get file ids by searching with exact name in the q parameter under label name
f_get_id <- gar_api_generator(baseURI = "https://www.googleapis.com/drive/v3/files",
http_header = "GET",
pars_args = list(q= "name = 'your_text_or_csv.txt'"))
#make the call
response_file <- f_get_id()
response_file$content
# $kind
# [1] "drive#fileList"
#
# $files
# list()
Totally understandable to have a smaller scope by default. The options are also a good tip as I thus far had opted for to set them through httr.
Description of use case: Use googleAuthR to authenticate and construct API calls to drive V3 API. Target machine is Debian,Linux VM that runs the gar_auth through a tunnel (not that it should matter to a great extent). Problem: Running gar_auth and an API call with the following code leads to a prompt to enable drive API from the console for the project in question. My understanding is that this would be unexpected behavior.
Code:
Which ends in:
Session info: