headers = {"Authorization": "Bearer " + my_access_token}
courses = requests.get("https://canvas.instructure.com/api/v1/courses", headers = headers)
Hello,--
I am trying to learn the API using Canvas API Lessons. I am having trouble with Lesson 6, the instructions are as followed:
Sweet, let's get moving now. For this next endpoint you'll need to be enrolled in at least one course. If you're not, go create one and you should be auto-enrolled as an instructor.I want you to get the list of courses you're enrolled in and tell me the
idof the first course returned by the API call.I am doing this lesson in Python using Requests for the API calls, when i run my program in the command line, the error says:
(u'status', u'unauthenticated')
(u'errors', {u'message': u'user authorization required'})I am confused because I thought I was authorized with my access token, the Canvas API lessons even say don't worry about OAuth yet because everything is done with the Access Tokens for now.
Here is my Python code for this lesson:
import requests
import json
def main():
# GET request for user information
# user_info = requests.get("https://canvas.instructure.com/api/v1/users/self/profile?access_token=<MY_ACCESS_TOKEN_HERE>") #
# Storing user information in dictionary called data
# user_info_dictionary = json.loads(user_info.text)
courses = requests.get("https://canvas.instructure.com/api/v1/courses")
courses_dictionary = json.loads(courses.text)
'''
for u in user_info_dictionary:
print(u, user_info_dictionary[u])
print("\n")
'''
for u in courses_dictionary:
print(u, courses_dictionary[u])
main()
How can I retrieve my list of courses?
---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.