0

if the api is not enabled, usually error will be like

HttpError: <HttpError 403 when requesting https://cloudresourcemanager.googleapis.com/v1/projects?alt=json returned "Cloud Resource Manager API has not been used in project 684373208471 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=xxxxxxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.". Details: "[{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Google developers console API activation', 'url': 'https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=xxxxxxxxx'}]}, {'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'SERVICE_DISABLED', 'domain': 'googleapis.com', 'metadata': {'consumer': 'projects/xxxxxxxxxxx', 'service': 'cloudresourcemanager.googleapis.com'}}]">

Does google provide API for enabling some api?

1 Answer 1

3

Google Cloud provides an API to enable APIs. This is called Service Usage API.

Service Usage REST API

Service Usage Client Libraries

Example code that I wrote to display a list of enabled APIs in Python:

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

project = 'projects/myproject'

service = discovery.build('serviceusage', 'v1', credentials=credentials)
request = service.services().list(parent=project)

response = ''

try:
    response = request.execute()
except Exception as e:
    print(e)
    exit(1)

# FIX - This code does not process the nextPageToken
# next = response.get('nextPageToken')

services = response.get('services')

for index in range(len(services)):
    item = services[index]

    name = item['config']['name']
    state = item['state']

    print("%-50s %s" % (name, state))

The output of this code looks similar to this (truncated for this answer):

abusiveexperiencereport.googleapis.com             DISABLED
acceleratedmobilepageurl.googleapis.com            DISABLED
accessapproval.googleapis.com                      DISABLED
accesscontextmanager.googleapis.com                DISABLED
actions.googleapis.com                             DISABLED
adexchangebuyer-json.googleapis.com                DISABLED
adexchangebuyer.googleapis.com                     DISABLED
adexchangeseller.googleapis.com                    DISABLED
adexperiencereport.googleapis.com                  DISABLED
admin.googleapis.com                               ENABLED
adsense.googleapis.com                             DISABLED

API Documentation for my example code

Sign up to request clarification or add additional context in comments.

4 Comments

you just show code to view which api is enabled, but how to enable them by api
@LukAron - Your question was Does google provide API for enabling some api?. I answered that and provided additional information to help you use the API. You did not specify a language. I thought Python would be an easy to read language to help you write your own software. This link shows the enable method to call: googleapis.github.io/google-api-python-client/docs/dyn/…
will highly appreciate it if python examples could be provided, I have read the doc too, but I find it difficult to use, also doesnt find relevant code in github.com/GoogleCloudPlatform/python-docs-samples
@LukAron - Your question has been answered. Please do not use comments to ask for more things. You can create another question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.