I am trying to use Google's TextToSpeech REST API on heroku.
I have a service account keyfile, which works fine locally, but I cannot figure out how I could make it work on Heroku, where the Google Cloud SDK is not installed. That is, consider this sample curl call from the quickstart:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) -H "Content-Type: application/json; charset=utf-8" --data "{
'input':{
'text':'Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > synthesize-output.txt
which depends on the bash command $(gcloud auth application-default print-access-token), which in turn depends on the google cloud SDK being installed (I have the mac version installed locally).
I looked into using the ruby client library, which I believe handles the authentication under the hood if it has the keyfile via the GOOGLE_CLOUD_KEYFILE_JSON env variable, but it does not appear to support TextToSpeech.
How can I make TextToSpeech API calls on Heroku?
You really just need to use the service account credentials to get an access token via OAuth 2.0. You can do this manually or use an SDK. Google as a set of Speech-to-Text Client Libraries at the link here. There are a few languages supported including Ruby, as well as C#, Go, Java, Node.js, PHP and Python:
https://cloud.google.com/speech-to-text/docs/reference/libraries#client-libraries-install-go
You can install the Ruby SDK with the following:
$ gem install google-cloud-speech
Then add the filepath to your credentials files as an environment variable:
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to[FILE_NAME].json"
I use Go and have a Google Text-to-Speech example here calling both text.synthesize (like your example) and voices.list. This example stores the Google key file contents in an environment variable which makes it easy to read from a Heroku instance. While this uses the google/google-api-go-client SDK, I just noticed and will consider upgrading to GoogleCloudPlatform/google-cloud-go now.
https://github.com/grokify/googleutil/blob/master/texttospeech/v1beta1/examples/quickstart/main.go
This retrieves an access token and then instantiates the Google Go Client SDK:
https://github.com/google/google-api-go-client
The Google Go SDK supports Text-to-Speech here:
https://github.com/google/google-api-go-client/tree/master/texttospeech/v1beta1
Go is easy to get on to Heroku as well using godep as documented here:
https://devcenter.heroku.com/articles/go-support
I also have a scaffolding app that will create the files you need to enable the "Deploy to Heroku" button for a Go app here:
https://github.com/grokify/goheroku
If you use Go and have any questions let me know.
Related
I'm using Deno instead of node as a runtime, which makes me unable to use firebase-admin. I would like to implement the listUsers from the admin sdk in REST, but have not found any REST api references. Is there a way to use the firebase-admin sdk with REST?
You are looking for the Identity Toolkit APIs, the accounts:batchGet to be specific. You'll need an access token to use those APIs since you cannot use default credentials with the REST API. Checkout the documentation for the same.
You can use the API explorer linked above to test APIs from the browser itself.
So, I've followed the documentation found here.
I then created an oauth 2.0 web application here.
After I took the client ID and I used it in the Manage API Client Access for the GSuite Admin following the documentation here to add the scopes. However, when I go to my app and I hit the "Sign in with Google" I get a:
400 Invalid Scopes
{invalid=['https://www.googleapis.com/auth/userinfo.profile, https://www.googleapis.com/auth/userinfo.email']}
Both of the scopes above have been added to the Manage API Client Access screens.
Any steps I might be missing?
TLDR; Github pipeline + docker build args with spaces are a no-go. Use secrets and envs.
Found the solution. The issue was that I was defining my scopes in the CI pipeline (github yml) and passing it to my docker file as a build arg which was being converted to an ENV. This didn't work well since there was a space in the string. I moved the two scopes to a github secret and exported it as an ENV which is then secure env'd in the docker file.
i have a question about getting client secret.
in google API doc, we need to enable and download JSON file from google console API. secret->credentials->API.
so in development that totally works fine. so i have a problem when in production. my app need get the API, but how to get client secret from code?
so while the user login/sign up. the user should not go and enable API first at the console.
its that possible to download client secret from code?
thanks
There is no API for Google Developer console. The only way to create a new client, enable APIs for it and get the Client secret. is to do so on the Google Developer console.
It is not possible to programmaticlly download the client secret.
It's fairly easy to get or derive a Dropbox Public Link URL, but that exposes your static User ID. Is there a way to get a Shared Link URL programmatically?
I've seen references to an Android function called getShareURL(), but I'm looking for a Mac OS X AppleScript, or some other desktop scripting solution.
I just recently had a need to do this from a bash script. This will also work in Mac OS X, since it supports bash and the curl utility:
Go to the Dropbox developer console (https://www.dropbox.com/developers/apps), login to your Dropbox account, and click the "Create App" button. In the settings for your app, scroll to the OAuth2 section and click the "Generate" button under "Generated access token". You'll need this token to access the Dropbox API.
In your bash script, insert the following:
DROPBOX_TOKEN="<your dropbox token generated in step 1>"
FILENAME="<file you want to share>"
JSON=`curl -s --header "Authorization: Bearer $DROPBOX_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"path\": \"/$FILENAME\",\"settings\": {\"requested_visibility\": \"public\"}}" \
https://api.dropbox.com/2/sharing/create_shared_link_with_settings`
This will give you back a JSON response containing information about the link. You'll need to parse out the JSON response to get the url, which you can do with a simple sed or awk script.
NOTE: The link you get back from this can be shared publicly, but be aware that the access token you got from the developer console is not to be shared. If your script is going to be accessible by someone other than you (the owner of the Dropbox account), then you'll need to take additional steps to authenticate the user with OAuth instead of using the generated token. In my case, the script runs on my machine and just sends the generated links out through an automated process, so the script is not visible to anyone but me. Anyone with that access token will have full control of your Dropbox account through the API, so treat it like you would a password.
I have a marketplace app that I'd like to use to access the Google Drive API. I'm currently using the gdata API using 2-legged OAuth. My understanding is that the new Google APIs, including Google Drive API do not support 2-legged OAuth.
How can I access the Google Drive API for my customers' domain without asking each of my customers's users for individual permission?
On my Google Apps Marketplace Vendor page, there is a link to the Google APIs Console, with a project linked to my Marketplace App, but there is no option to create an OAuth 2.0 Client ID. I can only create a Simple API key.
Apparently, you used to be able to use the two-legged OAuth credentials along with the server api key to authenticate, but it looks like that's no longer the case. I tried to authenticate using this method with an old Google API .net sdk, but got a 401. I downloaded the newest sdk, and two-legged OAuth is completely missing. I checked out a copy of the Ruby sdk, because it was used in the video "Google Drive SDK: Using the Drive API with the Google Apps Marketplace", but it looks like (I don't know Ruby) it explicitly forbids two-legged OAuth:
case authorization
when :oauth_1
STDERR.puts('OAuth 1 is deprecated. Please reauthorize with OAuth 2.')
I feel like Google is intentionally ignoring my questions about this topic.
You can use domain-wide delegation to access users' data without asking each user. Details are explained on https://developers.google.com/drive/delegation