Skip to content

Commit

Permalink
notebook added
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Dec 26, 2023
1 parent c2a2324 commit 1d7b9f0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions examples/python_notebook/user_auth_client_secret.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"authorship_tag": "ABX9TyMzCk4oTPbxmEWIM3hi9hYH",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/max-ostapenko/6745874f9e7fbb0d8971b97e656881b7/google_auth_example.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"from google_auth_oauthlib.flow import Flow\n",
"from google.colab import userdata\n",
"from IPython.display import display, HTML\n",
"\n",
"# Create Desktop client ID\n",
"# https://console.cloud.google.com/apis/credentials\n",
"# and add client_id and client_secret to notebook secrets\n",
"\n",
"# Define required OAuth scopes\n",
"# https://developers.google.com/identity/protocols/oauth2/scopes\n",
"SCOPES = [\"https://www.googleapis.com/auth/calendar\"]\n",
"\n",
"flow = Flow.from_client_config(\n",
" {\n",
" \"installed\": {\n",
" \"client_id\": userdata.get('client_id'),\n",
" \"client_secret\": userdata.get('client_secret'),\n",
" \"redirect_uris\": [\"http://localhost\"],\n",
" \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n",
" \"token_uri\": \"https://accounts.google.com/o/oauth2/token\"\n",
" }\n",
" },\n",
" SCOPES,\n",
" redirect_uri='urn:ietf:wg:oauth:2.0:oob'\n",
")\n",
"\n",
"auth_url, _ = flow.authorization_url(prompt='consent')\n",
"display(HTML(f'Click <a href=\"{auth_url}\" target=\"_blank\">here</a> to authorize access.'))\n",
"\n",
"code = input('Enter the authorization code: ')\n",
"flow.fetch_token(code=code)\n",
"credentials = flow.credentials"
],
"metadata": {
"id": "GdC23pqjE5oq"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import googleapiclient.discovery\n",
"service = googleapiclient.discovery.build('calendar', 'v3', credentials=credentials)\n",
"service.events().list(calendarId='primary', maxResults=10).execute()"
],
"metadata": {
"id": "T7e-66wwpowV"
},
"execution_count": null,
"outputs": []
}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 1d7b9f0

Please # to comment.