Skip to content

LightningDev/Google-Calendar-API-CSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Google-Calendar-API-.NET#

Wrapper classes for using Google Calendar API

This is my wrapper classes to handle the REST method in Google Calendar API. Use this if you don't want to use Google Library for .NET. It's written in C#.

#Prepare:# Json library for .NET ( Json.NET)

#Classes structure:#

  • APIWrapper.cs: Main class for calling the Google Calendar request (Insert, Update, Delete, Get)
  • GoogleCalendar.cs
  • GoogleCalendarList.cs
  • GoogleDateTime.cs
  • GoogleEvent.cs
  • GoogleEventList.cs
  • .GoogleToken.cs
  • WebUtils.cs: Web request implementations (GET, POST, PUT, DELETE)

#How to use:#

Authorizing the user permission

string authURL = APIWrapper.GetAuthenticateUrl("User gmail address");
After this you can use any methods you want to get the aut horized code from user after they accept or cancel.
For example: Response.Redirect(authURL);
After that, either use:
string authCode = Request.QueryString["code"]; // If user accept
string errorCode = Request.QueryString["error"]; // otherwise, they cancel it
This is just an example, you can write ashx file in ASP.NET if you want, the implementation how to get an authorization code depends on you.

Get the refresh and access token

To send the request to Google, you must have the token.
APIWrapper wrapper = new APIWrapper();
There are 2 functions, 1 return the GoogleToken object, the other is string of token.
GoogleToken refreshToken = wrapper.GetRefreshTokenObject(authCode);
string refreshToken = wrapper.GetRefreshToken(Code);
To get the access token, you must have refresh token.
GoogleToken accessToken = wrapper.GetAccessTokenObject(refreshToken);
string accessToken = wrapper.GetAccessToken(accessToken);
After this, store it into database or anywhere you want.

Get the list of calendar

Set the access token to the APIWrapper after you got it, then just simply call method GetCalendarList(), this will return the list of GoogleCalendar object. (modify it with GoogleCalendarList if you want).

List calendarList = wrapper.GetCalendarList();

Create a new calendar

This method will return the new object GoogleCalendar after you insert it.
GoogleCalendar calendar = wrapper.InsertCalendar("calendar name");

Update the calendar

Modify at your own if you want to update more information.
GoogleCalendar calendar = wrapper.UpdateCalendar(calendar ID,"calendar new name");

About the event, it's all the same as calendar.

About

Wrapper classes for using Google Calendar API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages