问题
I'm creating a lot of batched requests and I want to keep track of which ones are successful and which ones error. I'm using all kinds of different requests with the Google Classroom API V1.
I want to set the content-ID to a unique value and reference it in the callbacks. Any help would be appreciated, especially in C#.
Here is a sample for adding a course deletion to a batch request:
requests[CurrentBatch].Queue<GoogleCourse>(serviceCredential.Service.Courses.Delete(course.Id), (content, error, i, message) =>
{
if (content != null)
{
//add the classroom
GoogleClassroom.DAL.Datamodule.SaveGoogleCourseIdByNameAndUser(content.Id, content.Name, content.OwnerId);
log.Write("Successfully Added\n");
}
if (error != null)
{
log.Write("error:" + error.ToString() + "\n");
}
if (message != null)
{
log.Write("message:" + message.Content.ReadAsStringAsync().Result.ToString() + "\n");
}
});
回答1:
Unfortunately the .NET client doesn't provide an easy way to set the Content-ID header for specific request in the batch. I've tried a few methods to manually set the Content-ID header but without success. The best alternative at the moment is to use the index of the request / response to link them together, and the index is passed into the callback handler as the 3rd parameter.
来源:https://stackoverflow.com/questions/32637718/how-to-set-the-content-id-in-a-google-classroom-api-v1-request