r-lib / gmailr

Access the Gmail RESTful API from R.
https://gmailr.r-lib.org
Other
229 stars 56 forks source link

unable to authenticate through json file #102

Closed vikram-rawat closed 5 years ago

vikram-rawat commented 6 years ago

I am trying to schedule a task of downloading attachments from emails and uploading them to a website after a certain manipulation in data.

but I am not able to authenticate my gmail with a credential file.

I have the file. when I run

use_secret_file('D:/R_CODE/David_lal/client_secret_511687295850-3pegdu3n0t2f8iu826m3cl4n1nklb08f.apps.googleusercontent.com.json')

it gives me no error at all.

but when I try to run a code.

messages(search = 'Stock File Provision',
         label_ids = "INBOX",1)[[1]]$messages[[1]]$id %>% 
    message() %>% 
    save_attachments(path = 'D:/R_CODE/David_lal/data/temp/'
                    ,user_id = 'me')

it gives me this error

Error in itr(...) : Unauthorized (HTTP 401).

I have a valid credential file. Which I have created by following the mentioned step on your site.

Please help me out here.

rdrr1990 commented 5 years ago

I am having trouble with this json authentication too. Having run use_secret_file line-by-line, the structure of the json appears to be different than anticipated.

info <- jsonlite::fromJSON(readChar("path/to/myproject-*****.json", nchars = 1e+05))
info$installed$client_id
## [1] NULL

Instead, the client id is just found in info$client_id and info$installed is NULL. There doesn't seem to be any client_secret. Not sure if private_key is what they call that now or ...

> names(info)
## [1] "type"                        "project_id"                 
## [3] "private_key_id"              "private_key"                
## [5] "client_email"                "client_id"                  
##  [7] "auth_uri"                    "token_uri"                  
## [9] "auth_provider_x509_cert_url" "client_x509_cert_url"  
jimhester commented 5 years ago

This should be fixed by https://github.com/r-lib/gmailr/pull/113