I'm getting the following error when I try to post to the Mirror API using Google's .NET API.
Message "Google.Apis.Requests.RequestError\r\nRequired [400]\r\nErrors [\r\n\tMessage[Required] Location[ - ] Reason[required] Domain[global]\r\n]\r\n" string
The program I'm writing is loaded as a plugin (.dll) from a parent .Net program. When i run my code as a standalone program, I do not see this error. I was wondering if anyone else might have run into a similar situation or could guide me on what to look at?
The code I'm using is taken from Googles Mirror example code:
public static TimelineItem InsertTimelineItem(
String text, String contentType, Stream attachment,
String notificationLevel)
{
TimelineItem timelineItem = new TimelineItem();
timelineItem.Title = text;
timelineItem.Text = text;
if (!String.IsNullOrEmpty(notificationLevel))
{
timelineItem.Notification = new NotificationConfig()
{
Level = notificationLevel
};
}
try
{
if (!String.IsNullOrEmpty(contentType) && attachment != null)
{
// Insert both metadata and media.
TimelineResource.InsertMediaUpload request = mirrorService.Timeline.Insert(
timelineItem, attachment, contentType);
request.Upload();
return request.ResponseBody;
}
else
{
HttpRequestMessage req= mirrorService.Timeline.Insert(timelineItem).CreateRequest();
string content = req.Content.ReadAsStringAsync().Result;
bool? pretty=mirrorService.Timeline.Insert(timelineItem).PrettyPrint;
// Insert both metadata and media.
return mirrorService.Timeline.Insert(timelineItem).Execute();
}
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
return null;
}
}
The exception is fired at the final "return mirrorService.Timeline.Insert" statement.
I've recompiled the Google Mirror API to use a different version of Newtonsoft.JSON . This has solved the issue. The parent program was using a different version of Newtonsoft.JSON, so recompiling the code targeting this version has fixed the issue.
The source code for Google.Apis.Mirror.v1 can be downloaded from https://google-api-client-libraries.appspot.com/download/library/mirror/v1/csharp