code: def get_default_project_id():
    
    # Try getting default project id from gcloud. If it fails try config.json.
    try:
      proc = subprocess.Popen(['gcloud', 'config', 'list', '--format', 'value(core.project)'],
                              stdout=subprocess.PIPE)
      stdout, _ = proc.communicate()
      value = stdout.strip()
      if proc.poll() == 0 and value:
        if isinstance(value, six.string_types):
          return value
        else:
          # Hope it's a utf-8 string encoded in bytes. Otherwise an exception will
          # be thrown and config.json will be checked.
          return value.decode()
    except:
      pass
  
    config_file = os.path.join(get_config_dir(), 'config.json')
    if os.path.exists(config_file):
      with open(config_file) as f:
        config = json.loads(f.read())
        if 'project_id' in config and config['project_id']:
          return str(config['project_id'])
  
    if os.getenv('PROJECT_ID') is not None:
      return os.getenv('PROJECT_ID')
    return None
docs: Get default project id from config or environment var.
  
    Returns: the project id if available, or None.