Skip to content

Instantly share code, notes, and snippets.

@jramnai
Created May 25, 2022 12:29
Show Gist options
  • Save jramnai/b711aad0dbd29879608928a1778cfd72 to your computer and use it in GitHub Desktop.
Save jramnai/b711aad0dbd29879608928a1778cfd72 to your computer and use it in GitHub Desktop.
import requests
def get_access_token_detail():
"""
This return the access token
"""
api_url = "https://lms.com/oauth2/access_token"
data = {
'grant_type': "client_credentials",
'client_id': {client_id},
'client_secret': {client_secret},
}
return requests.request("POST", api_url, verify=False, data=data)
def get_user_profile_info(access_token_detail. username):
"""
This returns user profile info
"""
api_url = "https://lms.com/api/user/v1/accounts/" + username
headers = {
'authorization': access_token_detail.json()['token_type'] + " " + access_token_detail.json()['access_token'],
}
response = requests.request(
"GET", api_url, verify=False, headers=headers
)
fetched_response = response.json()
return fetched_response
access_token_detail = get_access_token_detail()
user_info = get_user_profile_info(access_token_detail, "edx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment