Warm tip: This article is reproduced from stackoverflow.com, please click
authentication google-calendar-api http java

Google Calendar API example without libraries

发布于 2020-04-08 23:46:48

I'm looking for a very simple example of using the Google Calendar API using HTTP GET or POST

All there examples require these huge libraries for language X. I just want a raw http example that would work in any language and require no libraries.

i.e. https://www.googleapis.com/calendar/v3/users/me/calendarList/primary?key=mykey

But of course this does not work, I don't think there is a key option for your Google API key, and you need to authorize it somehow.

A raw example in Java or JavaScript would be ideal,

Something like,

HttpPost request = new HttpPost("https://www.googleapis.com/calendar/v3/users/me/calendarList/primary?key=mykey");
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY),
new UsernamePasswordCredentials(user, password));
HttpResponse response = client.execute(request);

But.. that works, and what are user/password or how to validate Auth...

Any help is vastly appreciated.

Questioner
James
Viewed
80
2017-05-23 20:06

This question was answered in this post.

The answer post references a how2 that shows you how to call any google auth API in three simple steps using just HTTP GET/POST and not requiring any client libraries.

I spent over a day trying to get something working using Google's how2s and client libraries, and did not end up with anything I could use. But following this how2, I got it working in under and hour in my app. Thanks a lot to the blogger.

call Google auth API using Apache HttpClient