googleapis / google-auth-library-python

Google Auth Python Library
https://googleapis.dev/python/google-auth/latest/
Apache License 2.0
773 stars 302 forks source link

Documentation for Indexing API still uses deprecated oauth2client instead of google-auth and never mentions to install either #1453

Closed xuiqzy closed 5 months ago

xuiqzy commented 8 months ago

Documentation for Indexing API is still using old oauth2client library and not google-auth. It also never mentions to install either oauth2client or google-auth but then gives code samples that won't work with just installing google-api-python-client. Please update both issues.

The deprecation page of oauth2client said to file a bug here by linking here.

clundin25 commented 8 months ago

Hi @xuiqzy, thank you for your report!

I put a quick sample together while we work on updating the docs.

from google.auth import default
from google.auth.transport.requests import AuthorizedSession

SCOPES = [ "https://www.googleapis.com/auth/indexing" ]
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"

credentials, _ = default(scopes=SCOPES)
authed_session = AuthorizedSession(credentials=credentials)

# Define contents here as a JSON string.
# This example shows a simple update request.
# Other types of requests are described in the next step.

content = """{
  \"url\": \"http://example.com/jobs/42\",
  \"type\": \"URL_UPDATED\"
}"""

response = authed_session.request('POST', ENDPOINT, json=content)
print(response.status_code)
print(response.text)

I did not test it, but I hope it can unblock you in the interim.