Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

python - {"error_description": "Invalid Client Id", "error": "invalid_client"} for postman. How to connect to Collab Tech preview using REST API | Blackboard

I want to do a rest api test with Postman.

The steps I need to follow are written at

https://github.com/blackboard/BBDN-Collab-Postman-REST

and

https://www.youtube.com/watch?v=-mdRZ_1-Dzg&ab_channel=BbDevSupport

I can follow step by step what I need to do from the video at this address.

I am getting this error even though I have followed all the steps.

{
    "error_description": "Invalid Client Id",
    "error": "invalid_client"
} 

I'm sure the URL, api key and secret I want to test are correct because when I try it with code it works.

I have the test.py code below and when I run this code I get the output in the picture.



# Before run this py install requirements.txt

import json
import requests
import time
import jwt
import datetime
from dateutil import tz
import ssl
import sys
import os

key = "Your Key"
secret = "Your Secret"
url = "https://eu-lti.bbcollab.com/collab/api/csa"

headers = {
    'typ' : 'JWT',
    'alg': "RS256"     
}

claims = {
    "iss" : key,
    "sub" : key,
    "exp" : datetime.datetime.utcnow() + datetime.timedelta(minutes = 5) 
}

assertion = jwt.encode(claims, secret)

payload = {
    'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
    'assertion' : assertion
}

print(assertion)

token_endpoint = url + '/token'
r = requests.post(token_endpoint, data=payload, auth=(key, secret), verify=True)


print("[auth:setToken()] STATUS CODE: " + str(r.status_code) )
#strip quotes from result for better dumps
res = json.loads(r.text)
print("[auth:setToken()] RESPONSE: 
" + json.dumps(res,indent=4, separators=(',', ': ')))

token = ""

if r.status_code == 200:
    parsed_json = json.loads(r.text)
    token = parsed_json['access_token']
else:
    print("can not get token")
    exit()


def getRecordings(url, token, limit, offset):
    authStr = 'Bearer ' + token
            
    payload = {
        'limit' : limit,
        'offset': offset
    }

    args = "&".join(["%s=%s"%(k,v) for k,v in payload.items()])

    r = requests.get(url + '/recordings?' + args, headers={ 'Authorization':authStr,'Content-Type':'application/json','Accept':'application/json' }, json=payload, verify=True)
            
    if r.status_code == 200:
        res = json.loads(r.text)
        #print("Recording: " + json.dumps(res,indent=4, separators=(',', ': ')))
        return res
    else:
        return None

def getRecordingUrl(url, token, id):
    authStr = 'Bearer ' + token
    r = requests.get(url + '/recordings/' + id + "/url?disposition=download", headers={ 'Authorization':authStr,'Content-Type':'application/json','Accept':'application/json'}, verify=True)
        
    if r.status_code == 200:
        res = json.loads(r.text)
        return res["url"]
    else:
        return None


records = getRecordings(url, token, 10, 0)


for rec in records["results"]:
    id = rec["id"]

    rec_url = getRecordingUrl(url, token, id)

    if not os.path.exists("./recordings"):
        os.makedirs("./recordings")

    if rec_url:
        name = "./recordings/" + rec["name"] + ".mp4"
        print ("Downloading -> %s" % (name))
        r = requests.get(rec_url, allow_redirects=True)
        with open(name, 'wb') as f:
            f.write(r.content)

Output of the test.py

Output of the test.py

My main goal is to download the records in the blackboard collab. When i want to test this with postman i fail.

Has anyone encountered such a problem before? How can I solve this problem?

question from:https://stackoverflow.com/questions/65936966/error-description-invalid-client-id-error-invalid-client-for-postma

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...