0

我正在从事一个游戏化项目,其目标是使用 Unity 构建 WebGL 游戏,并使用 canvas LMS API 将最终分数作为作业成绩发布。我需要知道两件事:现在如何使用不记名令牌进行身份验证(我已经知道如何创建令牌,以后需要使用 auth 2.0)以及如何使用 UnityWeb 请求或类似方法发布作业成绩。我尝试使用restsharp,vs代码识别它,但Unity没有。还尝试与 node.js 建立连接,Unity 和 node.js 连接成功,但我使用的节点包装器不起作用。

在最糟糕的情况下,我希望能够对作业发表评论(我会将最终成绩作为字符串传递)。

这是我用 httpWebRequest 尝试过的:

string api_token = "bearer token here";
    //initializing HttpWebRequest object   
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("domain here");
    IWebProxy theProxy = request.Proxy;
    if (theProxy != null)
    {
        theProxy.Credentials = CredentialCache.DefaultCredentials;
    }
    CookieContainer cookies = new CookieContainer();
    request.UseDefaultCredentials = true;
    request.CookieContainer = cookies;
    request.ContentType = "application/json";
    request.CookieContainer = cookies;
    // write the "Authorization" header  
    request.Headers.Add("Authorization", "Basic " + api_token);
    request.Method = "POST";
    // get the response  
    //WebResponse response = request.GetResponse();  
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        StreamReader reader = new StreamReader(response.GetResponseStream());
        Debug.Log(reader.ReadToEnd());
    }

我需要节点包装器来进行身份验证和发布请求。节点包装器:c10。我已经尝试过很多次node-canvas-api

我可以访问 api 并使用邮递员发布。

4

1 回答 1

0

我发现我可以在邮递员上使用代码片段来检索某种语言的请求。有了这个,我不再需要 python API,因为我可以直接获取代码。我仍然不知道为什么Unity无法识别restSharp,但是python解决了我的问题。因为我很难找到如何在 Canvas lms 上发布成绩和评论,所以我将把 PATH 留在这里给遇到同样问题的人:

PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id

查询参数是:comment[text_comment] 和submission[posted_grade]。

于 2021-07-09T03:28:33.677 回答