http POST Formatting Issue - As array, list?
I am attempting to make a "Freebusy" request to connect to Google Calendar
API. Currently I am stuck on formatting the http POST. I am getting an
error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
I am attempting to format the request like this:
{
"timeMin": datetime,
"timeMax": datetime,
"timeZone": string,
"groupExpansionMax": integer,
"calendarExpansionMax": integer,
"items": [
{
"id": string
}
]
}
And am currently doing this to format it:
public void freeBusyRequest(String accessToken, String calendarID, int
day, int month, int year) throws Exception{
JSONObject jsonObj =
makePOST_TEST("https://www.googleapis.com/calendar/v3/freeBusy", new
String[]{
"timeMin", date1,
"timeMax", date2,
"items[]", calendarID,
"timezone", "Canada/Toronto"}, accessToken );
}
public JSONObject makePOST_TEST(String hostURL, String[] stringPairs,
String accessHeader) throws Exception {
//Create an HTTP post request
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(hostURL);
List<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>(stringPairs.length/2 - 1);
for (int i = 0; i < stringPairs.length; i += 2) {
nameValuePairs.add(new BasicNameValuePair(stringPairs[i],
stringPairs[i+1]));
}
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
org.apache.http.HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
//...
}
No comments:
Post a Comment