code: def get_service_account_credentials(private_key):
      
  
      import google.auth.transport.requests
      from google.oauth2.service_account import Credentials
  
      is_path = os.path.isfile(private_key)
  
      try:
          if is_path:
              with open(private_key) as f:
                  json_key = json.loads(f.read())
          else:
              # ugly hack: 'private_key' field has new lines inside,
              # they break json parser, but we need to preserve them
              json_key = json.loads(private_key.replace("\n", "   "))
              json_key["private_key"] = json_key["private_key"].replace(
                  "   ", "\n"
              )
  
          json_key["private_key"] = bytes(json_key["private_key"], "UTF-8")
          credentials = Credentials.from_service_account_info(json_key)
          credentials = credentials.with_scopes(SCOPES)
  
          # Refresh the token before trying to use it.
          request = google.auth.transport.requests.Request()
          credentials.refresh(request)
  
          return credentials, json_key.get("project_id")
      except (KeyError, ValueError, TypeError, AttributeError):
          raise pandas_gbq.exceptions.InvalidPrivateKeyFormat(
              "Detected private_key as {}. ".format(
                  "path" if is_path else "contents"
              )
              + "Private key is missing or invalid. It should be service "
              "account private key JSON (file path or string contents) "
              'with at least two keys: "client_email" and "private_key". '
              "Can be obtained from: https://console.developers.google."
              "com/permissions/serviceaccounts"
          )
docs: DEPRECATED: Load service account credentials from key data or key path.