Search code examples
ruby-on-railsgoogle-contacts-apigoogle-earth-engine

Google Earth Engine REST API Authentication from Ruby fails


I'm trying to use a service account to make an API request to https://earthengine.googleapis.com/v1alpha/projects/{my-project}:listAssets?key={serviceKey}, but I always get 401 unauthorized.

 url = "https://earthengine.googleapis.com/v1alpha/projects/{project-id}:listAssets?key=ServiceAccountKey"
endpoint = URI.parse(url)
request = Net::HTTP::Get.new(endpoint.to_s)

response = Net::HTTP.start(endpoint.host, endpoint.port, use_ssl: true) { |http| http.request(request) }
JSON.parse(response.body)

Solution

  • I got the same issue in the past. You need to be accepted/enrolled first by the Google EarthEngine team in order to access the API.

    Signup for Earth Engine. Once you have been accepted, you will receive an email with additional information.

    To signup, follow instructions from the official Google docs here.

    It took 1 day in my case and I could then call the API smoothly.

    EDIT: The HTTP 401 response you are getting indicates invalid authentication credentials. In my case, the app connects using a Service Account. I followed instructions here and my app could connect smoothly to the Earth Engine. hope it helps