I am trying to call the Google API for mediaItems:search
to return a list of images. However I'm getting error 400 bad request back. If I don't set the body of the POST at all, I successfully get back images, but I need to filter them. How can make a successful call, filtering by date range?
string requestUri = "https://photoslibrary.googleapis.com/v1/mediaItems:search";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUri);
webRequest.Method = "POST";
webRequest.Headers.Add(string.Format("Authorization: Bearer {0}", accessToken));
webRequest.ContentType = "application/json";
string bodyData = "{\"pageSize\":25,\"filters\":{\"dateFilter\":{\"ranges\":[{\"startdate\":{\"year\":2023,\"month\":5,\"day\":4},\"endDate\":{\"year\":2023,\"month\":6,\"day\":4}}]}},\"pageToken\":\"\"}";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytes = encoding.GetBytes(bodyData);
webRequest.ContentLength = bytes.Length;
using (Stream requestStream = webRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
WebResponse userinfoResponse = await webRequest.GetResponseAsync();
Response is
The remote server returned an error: (400) Bad Request.