Skip to content

Commit b1a7707

Browse files
committed
Remove Classroom API calls from Walkthrough 3.
Minor cleanup to main.py in W2 and W3. Update W3 required modules. Change-Id: I394fc7d60dc14428cd8fca8b2acf49016b7160fb
1 parent 9f365dd commit b1a7707

File tree

5 files changed

+8
-30
lines changed

5 files changed

+8
-30
lines changed

flask/02-sign-in/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_api_request(request_type="username"):
116116
# Render the results of the API call.
117117
return flask.render_template(
118118
"show-api-query-result.html",
119-
data=json.dumps(fetched_data, indent=2), #flask.jsonify(courses),
119+
data=json.dumps(fetched_data, indent=2),
120120
data_title=request_type)
121121

122122

flask/03-query-parameters/main.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,8 @@
4848
# OAuth Consent Screen: https://console.cloud.google.com/apis/credentials/consent
4949
SCOPES = [
5050
"https://www.googleapis.com/auth/userinfo.profile",
51-
"https://www.googleapis.com/auth/userinfo.email",
52-
"https://www.googleapis.com/auth/classroom.courses.readonly",
53-
"https://www.googleapis.com/auth/classroom.addons.student",
54-
"https://www.googleapis.com/auth/classroom.addons.teacher",
51+
"https://www.googleapis.com/auth/userinfo.email"
5552
]
56-
CLASSROOM_API_SERVICE_NAME = "classroom"
57-
CLASSROOM_API_VERSION = "v1"
58-
59-
# An API key in your GCP project's credentials:
60-
# https://console.cloud.google.com/apis/credentials.
61-
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
6253

6354
# Point to a database file in the project root.
6455
DATABASE_FILE_NAME = os.path.join(os.path.abspath(os.path.dirname(__file__)),
@@ -180,7 +171,7 @@ def test_api_request(request_type="username"):
180171
Tests an API request, rendering the result in the "show-api-query-result.html" template.
181172
182173
Args:
183-
request_type: The type of API request to test. Can be "username" or "courses".
174+
request_type: The type of API request to test. Currently only "username" is supported.
184175
"""
185176

186177
if "credentials" not in flask.session:
@@ -203,26 +194,14 @@ def test_api_request(request_type="username"):
203194

204195
fetched_data = flask.session.get("username")
205196

206-
elif request_type == "courses":
207-
classroom_service = googleapiclient.discovery.build(
208-
CLASSROOM_API_SERVICE_NAME,
209-
CLASSROOM_API_VERSION,
210-
credentials=credentials,
211-
discoveryServiceUrl=
212-
f"https://classroom.googleapis.com/$discovery/rest?labels=ADD_ONS_ALPHA&key={GOOGLE_API_KEY}"
213-
)
214-
215-
fetched_data = classroom_service.courses().list(
216-
pageSize=10).execute().get("courses", [])
217-
218197
# Save credentials in case access token was refreshed.
219198
flask.session["credentials"] = credentials_to_dict(credentials)
220199
save_user_credentials(credentials)
221200

222201
# Render the results of the API call.
223202
return flask.render_template(
224203
"show-api-query-result.html",
225-
data=json.dumps(fetched_data, indent=2), #flask.jsonify(courses),
204+
data=json.dumps(fetched_data, indent=2),
226205
data_title=request_type)
227206

228207

@@ -384,6 +363,7 @@ def save_user_credentials(credentials=None, user_info=None):
384363

385364
existing_user = get_credentials_from_storage(
386365
flask.session.get("login_hint"))
366+
387367
if existing_user:
388368
if user_info:
389369
existing_user.id = user_info.get("id")
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Flask==2.0.2
2-
google_api_python_client==2.31.0
2+
Flask_SQLAlchemy==2.5.1
3+
google_api_python_client==2.33.0
34
google_auth_oauthlib==0.4.6
45
protobuf==3.19.1
56
requests==2.26.0

flask/03-query-parameters/templates/navbar.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
</li>
2323

2424
{% if session['username'] %}
25-
<li>
26-
<a href="{{url_for('test_api_request', request_type='courses')}}">Get Courses</a>
27-
</li>
2825
<li>
2926
<a href="{{url_for('test_api_request', request_type='username')}}">Get Username</a>
3027
</li>

flask/03-query-parameters/templates/signed-out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
<h2>Sign-out Complete!</h2>
2525
<hr>
2626
Your credentials have been cleared; you are logged out.
27-
You will be redirected to the add-on landing page in 5 seconds.
27+
You will be redirected to the authorization page in 5 seconds.
2828
</div>
2929
{% endblock %}

0 commit comments

Comments
 (0)