2016-09-30 50 views
0

下面的代碼適用於大多數的學生在教室裏時,他們提交asignment調用返回400錯誤,但它拋出一個400錯誤的異常對一些學生:ModifyAttachments使用C#客戶端庫

var classroom = GetClassroomService(); 

var studentSubmissionsResponse = classroom.Courses.CourseWork.StudentSubmissions.List(courseId, courseWorkId).Execute(); 
var submission = studentSubmissionsResponse.StudentSubmissions.FirstOrDefault(s => s.AssociatedWithDeveloper ?? false); 

var modifyAttachmentRequest = new global::Google.Apis.Classroom.v1.Data.ModifyAttachmentsRequest(); 

var link = new global::Google.Apis.Classroom.v1.Data.Link() { Url = url }; 
var attachment = new global::Google.Apis.Classroom.v1.Data.Attachment() { Link = link }; 

modifyAttachmentRequest.AddAttachments = new System.Collections.Generic.List<global::Google.Apis.Classroom.v1.Data.Attachment>(); 
modifyAttachmentRequest.AddAttachments.Add(attachment); 

submission = classroom.Courses.CourseWork.StudentSubmissions.ModifyAttachments(modifyAttachmentRequest, courseId, courseWorkId, submission.Id).Execute(); 

/// submission code is after this; the exception is thrown by the call above 

唯一的例外是:

The service classroom has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError 
Request contains an invalid argument. [400] 
Errors [ 
    Message[Request contains an invalid argument.] Location[ - ] Reason[badRequest] Domain[global] 
] 

不幸的是,C#客戶端庫目前不支持詳細的錯誤信息的顯示呢。

關於可能發生什麼的任何想法?如何解決問題?

回答

1

400意味着請求格式不正確。換句話說,客戶端發送給服務器的數據流並不遵循規則。

所以我會做的解決這個問題是啓動Fiddler,運行代碼並將請求隔離到端點。也許然後將無效請求與有效請求進行比較並確定差異。

+0

我希望我能做到這一點。當學生在(物理)課堂上完成作業時,會拋出異常。該錯誤消息表明存在無效參數。在那個調用中,改變的唯一參數是URL。我嘗試過使用我自己的帳戶失敗的網址,他們的工作。所以,這不是網址。其他學生的課程和課程工作。只留下提交.Id,但我認爲我正確得到提交。 –