ropensci / googleLanguageR

R client for the Google Translation API, Google Cloud Natural Language API and Google Cloud Speech API
https://code.markedmondson.me/googleLanguageR/
Other
195 stars 42 forks source link

How to get Authentication? #51

Closed englianhu closed 5 years ago

englianhu commented 6 years ago

Authentication The best way to authenticate is to use an environment file. See ?Startup. I usually place this in my home directory. (e.g. if using RStudio, click on Home in the file explorer, create a new TEXT file and call it .Renviron) Set the file location of your download Google Project JSON file in a GL_AUTH argument:

GL_AUTH=location_of_json_file.json

I try to browse over http://code.markedmondson.me/googleLanguageR/articles/speech.html but don;t know how to get authentication in order to use the functions.


library('googleLanguageR')
lnk <- 'https://scontent-yyz1-1.xx.fbcdn.net/v/t66.18014-6/42832823_1854945517918295_8803608342512894293_n.mp4?_nc_cat=110&efg=eyJ2ZW5jb2RlX3RhZyI6Im9lcF9oZCJ9&oh=08e0a1bce580184048cd33489d3c254c&oe=5C3DAE2F'
vfile <- tempfile()

if (file.exists(vfile)) {
+   vday <- gl_speech(vfile)
+   
+   play(vday)
+ } else {
+   download.file(lnk, vfile, mode = 'wb')
+   vday <- gl_speech(vfile)
+   #play(vday)
+ }
trying URL 'https://scontent-yyz1-1.xx.fbcdn.net/v/t66.18014-6/42832823_1854945517918295_8803608342512894293_n.mp4?_nc_cat=110&efg=eyJ2ZW5jb2RlX3RhZyI6Im9lcF9oZCJ9&oh=08e0a1bce580184048cd33489d3c254c&oe=5C3DAE2F'
Content type 'video/mp4' length 5844502 bytes (5.6 MB)
downloaded 5.6 MB

2018-10-18 22:42:25> No authorization yet in this session! 2018-10-18 22:42:25> NOTE: a .httr-oauth file exists in current working directory. Run authentication function to use the credentials cached for this session. Error: Invalid token

MarkEdmondson1234 commented 6 years ago

You need to follow the Installation steps to generate a service credential JSON file in a Google console.

englianhu commented 6 years ago

https://www.youtube.com/watch?v=zgwDQu-mCOc got the ga.aauth key via googleAnalyticsR::ga.auth('aauth') but not in googleLanguageR::gl.auth('gl.aauth')

> library('googleAnalyticsR')
2018-10-18 23:11:27> Default Google Project for googleAnalyticsR is now set.  
 This is shared with all googleAnalyticsR users. 
 If making a lot of API calls, please: 
 1) create your own Google Project at https://console.developers.google.com 
 2) Activate the Google Analytics Reporting API 
 3) set options(googleAuthR.client_id) and options(googleAuthR.client_secret) 
 4) Reload the package.
2018-10-18 23:11:27> Set API cache
2018-10-18 23:11:27> No environment argument found, looked in GA_AUTH_FILE
> ga_auth
function (token = NULL, new_user = FALSE, no_auto = FALSE) 
{
    if (!is.null(token)) {
        return(gar_auth(token = token))
    }
    needed <- c("https://www.googleapis.com/auth/analytics", 
        "https://www.googleapis.com/auth/analytics.readonly", 
        "https://www.googleapis.com/auth/analytics.manage.users.readonly", 
        "https://www.googleapis.com/auth/analytics.edit", "https://www.googleapis.com/auth/analytics.manage.users", 
        "https://www.googleapis.com/auth/analytics.provision")
    gar_auto_auth(needed, new_user = new_user, no_auto = no_auto, 
        environment_var = "GA_AUTH_FILE")
}
<bytecode: 0x000000000bdb72a0>
<environment: namespace:googleAnalyticsR>
> ga_auth('ga.aauth')
2018-10-18 23:12:47> No httr_oauth_cache file found at ga.aauth - creating new file.
Adding ga.aauth to .gitignore
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Token cache file: ga.aauth
> gl_auth('ga.aauth')
Error in parse_con(txt, bigint_as_char) : 
  lexical error: invalid char in json text.
                                       X                      (right here) ------^
> gl_auth('gl.aauth')
Error in gar_auth_service(json_file = json_file) : 
  file.exists(json_file) is not TRUE
> gl_auth('gl.oauth')
Error in gar_auth_service(json_file = json_file) : 
  file.exists(json_file) is not TRUE
> gl_auth('gl.auth')
Error in gar_auth_service(json_file = json_file) : 
  file.exists(json_file) is not TRUE
MarkEdmondson1234 commented 6 years ago

Ok, ignore that.

You need to create a service key there is a guide here https://cloud.google.com/video-intelligence/docs/common/auth

james-henderson93 commented 5 years ago

hey Mark,

I am having a similar problem with googleLanguageR.

2019-12-02 10:07:45> No authorization yet in this session! 2019-12-02 10:07:45> No .httr-oauth file exists in current working directory. Do library authentication steps to provide credentials. Error: Invalid token

library(googleAnalyticsR) ga_auth("ga.oauth") 2019-12-02 10:26:28> Default Google Project for googleAnalyticsR is set.
This is shared with all googleAnalyticsR users. If making a lot of API calls, please: visit: https://bit.ly/2Evk6hn for instructions on setting your own Google Project

Error: Path 'ga.oauth' does not exist

I have my json file and api key but for some reason I cannot get this authorised.

any help would be great, thanks.

MarkEdmondson1234 commented 5 years ago

Could you open this on googleAnalyticsR repo? https://github.com/MarkEdmondson1234/googleAnalyticsR

But looks like you need to review the setup guide on the website: https://code.markedmondson.me/googleAnalyticsR/articles/setup.html

james-henderson93 commented 5 years ago

yep but when using ga_auth() it takes me to the google webpage with an error.

  1. That’s an error.

Error: invalid_request Missing required parameter: client_id Learn more Request Details That’s all we know.

MarkEdmondson1234 commented 5 years ago

Ok looks like we need to see all your code you are attempting. Please open the issue on https://github.com/MarkEdmondson1234/googleAnalyticsR not here on https://github.com/ropensci/googleLanguageR