Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: third_party/gsutil/third_party/oauth2client/samples/oauth2_for_devices.py

Issue 1377933002: [catapult] - Copy Telemetry's gsutilz over to third_party. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Rename to gsutil. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/gsutil/third_party/oauth2client/samples/oauth2_for_devices.py
diff --git a/third_party/gsutil/third_party/oauth2client/samples/oauth2_for_devices.py b/third_party/gsutil/third_party/oauth2client/samples/oauth2_for_devices.py
new file mode 100644
index 0000000000000000000000000000000000000000..6b3b72ec267b5f084662bdf836167b551e0cc461
--- /dev/null
+++ b/third_party/gsutil/third_party/oauth2client/samples/oauth2_for_devices.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+
+# See: https://developers.google.com/accounts/docs/OAuth2ForDevices
+
+import httplib2
+from six.moves import input
+from oauth2client.client import OAuth2WebServerFlow
+from googleapiclient.discovery import build
+
+CLIENT_ID = "some+client+id"
+CLIENT_SECRET = "some+client+secret"
+SCOPES = ("https://www.googleapis.com/auth/youtube",)
+
+flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, " ".join(SCOPES))
+
+# Step 1: get user code and verification URL
+# https://developers.google.com/accounts/docs/OAuth2ForDevices#obtainingacode
+flow_info = flow.step1_get_device_and_user_codes()
+print("Enter the following code at {0}: {1}".format(flow_info.verification_url,
+ flow_info.user_code))
+print("Then press Enter.")
+input()
+
+# Step 2: get credentials
+# https://developers.google.com/accounts/docs/OAuth2ForDevices#obtainingatoken
+credentials = flow.step2_exchange(device_flow_info=flow_info)
+print("Access token: {0}".format(credentials.access_token))
+print("Refresh token: {0}".format(credentials.refresh_token))
+
+# Get YouTube service
+# https://developers.google.com/accounts/docs/OAuth2ForDevices#callinganapi
+youtube = build("youtube", "v3", http=credentials.authorize(httplib2.Http()))

Powered by Google App Engine
This is Rietveld 408576698