0
votes

I'm trying to connect to my Google Cloud Endpoints API that is running as an Appengine app:

@endpoints.api(name='helloworldendpoints', allowed_client_ids=["1234", "12345"], version='v1', auth_level=endpoints.AUTH_LEVEL.REQUIRED)
class HelloWorldApi(remote.Service):
...

The API request is as follows:

scopes = ["https://www.googleapis.com/auth/userinfo.email"]
credentials = ServiceAccountCredentials.from_json_keyfile_name("CloudEndpointsClient.json", scopes)

from httplib2 import Http
http_auth = credentials.authorize(Http())

from apiclient.discovery import build

api_root = 'https://myapp.appspot.com/_ah/api'
api = 'helloworldendpoints'
version = 'v1'
discovery_url = '%s/discovery/v1/apis/%s/%s/rest' % (api_root, api, version)
service = build(api, version, discoveryServiceUrl=discovery_url)


response = service.myFunction(myparameter = "123456").execute(http=http_auth)#
print response

The requests work well if I remove authentication requirements. I know that authentication works since the error changes if after authenticating.

The error message I'm getting is:

googleapiclient.errors.HttpError: https://my-app.appspot.com/_ah/api/helloworldendpoints/v1/obtainScoreFromEmail?myparameter=1234&alt=json returned "Access Not Configured. has not been used in project 123456789 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/helloworldendpoints/overview?project=123456789 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.">

I cannot enable the API in my Google Cloud Project, since the API does not exist.

1
when you know that the project does not exist, why are you not creating one?Rajat
The project does exist. What's not there is the API service to enable.Luka
Ok, so in the "Google Console > Library", you can go ahead and enable the api that you intend to use. Which particular api are you not able to findRajat
The problem here is that it's a custom Cloud Endpoints API called helloworldendpoints which is not available in the library.Luka

1 Answers

0
votes

What I found to work is a hack around. I used a user authentication (instead of server) on the same project for the same API which worked (https://cloud.google.com/endpoints/docs/frameworks/python/access_from_python).

After I switched back to my initial server auth. method it started working.