Code Examples

The easiest way to get started with the Cell ID State methods is to download the example script package (provided by your Google contact) and follow the instructions contained within. Alternatively, you can download a Google API client library and develop your own code to interact with the ISP Portal API.

Client Library

Google recommends you use the Python client library for the ISP Portal API. Python is available on most Unix-based systems.

To get the Python client library, do one of the following:

  1. Download the example script package (provided by your Google contact), which includes the Python client library and is ready to use.
  2. Visit the Developer's guide for the Python client library and download the client library to your machine. You will have to write your own code to make authenticated API calls.

Authentication

Requests made to the ISP Portal API must be authenticated so Google knows which network to return data for. First, follow the instructions from the Getting Started page and download the example script package (provided by your Google contact) to your computer. Then do the following:

  1. In the example script directory, replace the temporary private key file (key.p12) with the private key that was generated when you created your service account.
  2. In the example script directory, replace the service account email address file (service_account.txt) with the email address of your service account.

The following lines from the example Python script take a set of service account credentials (your service account email and the contents of your private key) and generate an HTTP object for signing API requests:

  # We have already read service_account.txt and key.p12 into the local
  # variables service_account_email and key.

  # Create a credential-wrapping object.
  credentials = client.SignedJwtAssertionCredentials(
    service_account_email,
    key,
    scope='https://www.googleapis.com/auth/isp_portal')

  # Create and authorize an httplib instance.
  http = httplib2.Http()
  http = credentials.authorize(http)

Calling API Methods

A complete list of methods can be found in the API Documentation section in the sidebar on the left. The following lines from the example Python script show how to construct and execute an API call to register the congestion state of a network cell:

  # Build an API service object from the ISP Portal API description.
  service = discovery.build(
    'ispportal',
    'v0',        # The current version of the ispportal API.
    http=http    # The authorized http instance from above.
  )

  # Build an updateCdma request body that sets network congestion level for 5min.
  expiresAt = int(time.time()) + 300
  body = {
    'network': {
      'countryCode': 123,
      'networkCode': 99,
      'locationAreaCode': 24,
      'cellId': 55
    },
    'state': {
      'attributeStates': {
        'attribute': { 'congestion': { 'level': 3 } },
        'expiresAt': expiresAt
      }
    }
  }

  # Call the updateCdma method.
  request = service.updateCdma(body=body)
  response = request.execute(http=http)

  # Print the request response
  print 'Response string: ' + response.status

  # Build an updateLte request body that sets network off-peak status for 2h.
  expiresAt = int(time.time()) + 7200
  body = {
    'network': {
      'countryCode': 123,
      'networkCode': 99,
      'cellId': 55
    },
    'state': {
      'attributeStates': {
        'attribute': { 'offpeak': { 'enabled': True } },
        'expiresAt': expiresAt
      }
    }
  }

  # Call the updateLte method.
  request = service.updateLte(body=body)
  response = request.execute(http=http)

  # Print the request response.
  print 'Response string: ' + response.status