0

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)
intotecho
  • 4,925
  • 3
  • 39
  • 54
Ghina
  • 3
  • 2
  • Try to elaborate. Explain what you did. Then show some code and where exactly you are getting which error. – Ekeko Nov 02 '20 at 10:46

1 Answers1

1

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

Marc
  • 2,183
  • 2
  • 11
  • 16
  • I'm already signed up to Google Earth Engine. I'm doing a REST API call from my app, I tried sending the key (the service key), I got 401. I tried to pass the client_id, I also got the same response 401. – Ghina Nov 02 '20 at 10:08
  • just added more details in my answer with the way I got in. hope it helps – Marc Nov 02 '20 at 10:27
  • Thanks for the reply ... I created a Service Account. However, I can't use ee.ServiceAccountCredentials as I'm doing this using Ruby on rails. – Ghina Nov 02 '20 at 11:21
  • In your case, I would create a cloud function (GCP or AWS lambda) to handle all the Earth Engine API in Node.js (or Python) and I would let the Ruby on Rails side simply make HTTP calls to your cloud function. So, your intermediate EE custom-API is abstracted away from your user-facing app, handling credentials & custom EE-related logic. – Marc Nov 02 '20 at 18:09
  • 1
    I was able to properly authenticate the request and get a response back. I had to set the account credentials in the omniauth initializer file using `gem 'omniauth-google-oauth2'` gem, and set the scope also which had to include the APIs scope mentioned in [here](https://developers.google.com/earth-engine/reference/rest/v1alpha/projects/listAssets). However I will try the approach you mentioned as I don't have access to (ee variable) when doing the REST API calls. – Ghina Nov 03 '20 at 08:12