I would be very interested in using AutoML translate
@dazuma @TheRoyalTnetennba Do either of you know the answer to this question?
Is there something I can use in the meantime until AutoML is supported?
The AutoML REST API requires 'gcloud auth print-access-token' as authentication, not entirely sure how to obtain this authentication key on a rails server
This question has also been asked for Google API Client in googleapis/google-api-ruby-client#721.
I spoke with the AutoML team, and the current plan is to produce the Ruby clients during early 2019. Until then, you can talk directly to the REST API as documented here.
@echan00 For authentication from Rails, our recommendation is to create a service account. Since as you mention, the access token from gcloud auth probably isn't available on a production rails server, since you probably don't have gcloud installed and logged in with your google account there.
Some getting started info is here. The steps are:
require "googleauth"
scope = "https://www.googleapis.com/auth/cloud-platform"
creds = File.open "/path/to/service_account_key.json" do |io|
Google::Auth::ServiceAccountCredentials.make_creds json_key_io: io, scope: scope
end
access_token_info = creds.fetch_access_token!
access_token = access_token_info["access_token"]
conn = Faraday.new(
url: "https://automl.googleapis.com",
headers: {"Authorization" => "Bearer #{access_token}",
"Content-Type" => "application/json"})
response = conn.post # etc.
Access tokens expire after a period of time. If it does, fetch a new one from the creds object by calling fetch_access_token! again.
If you are running on Google infrastructure (such as Google Compute Engine, Kubernetes Engine, or App Engine), you can also use the "default" service account associated with the server you're running on. That makes it easier to get an access token. You don't need to create your own service account or download a key. Instead, do this:
require "googleauth"
scope = "https://www.googleapis.com/auth/cloud-platform"
creds = Google::Auth.get_application_default scope
access_token_info = creds.fetch_access_token!
access_token = access_token_info["access_token"]
Then use the access token in the Authorization header as above.