Operate Google Calendar with C # code

Source: Internet
Author: User
Original article: operate Google Calendar with C # code

Topic

Use the Google. Net APIs client library and the C # code to create meeting invitations in the Google Calendar.

Background

Recently, Google released the. NET APIs client library, which can finally conveniently call Google APIs through. Net/C # code.

We have this requirement, so we tried it. The requirement is as follows: by calling the Google Calendar API, You can automatically create a Google Calendar event for the weekly meeting, invite and notify attendees, and the invitee can modify the calendar item. Previously, this operation was manually performed on the Google Calendar web page.

Preparations

1. download and install the Google data api sdk, which is mainly used to reference three of the three sets. This SDK also contains the source code of Google. Net APIs client library. It is precisely because of the source code that we encounter in use that we can quickly solve the problem.

2. Read the reference documents and sample code data API developer's Guide:. net. Focus on creating single-occurrence events (our task is to create a calendar item ). The sample code only creates a resume calendar item containing the title, content, location, and time. Our requirements also include: a) Invite participants (participant); B) notification to participants (notifications); c) the invitee can modify the calendar item (guestscanmodify ).

Problems

Google. net APIs client library does not implement the Gcal: guestscanmodify attribute (setting this attribute allows the invitee to modify the calendar item). We will refer to it later. the source code of net APIs client library is implemented by itself. The Code is as follows:

public class GuestsCanModify : EnumConstruct
{
public GuestsCanModify()
: base("guestsCanModify",
GDataParserNameTable.gCalPrefix,
GDataParserNameTable.NSGCal)
{
}

public GuestsCanModify(string value)
: base("guestsCanModify",
GDataParserNameTable.gCalPrefix,
GDataParserNameTable.NSGCal, value)
{
}
}

CodeImplementation

Create a new project in vs2010 and add three references: "Google. gdata. extensions. DLL "," Google. gdata. calendar. DLL "," Google. gdata. client. DLL ".

The code for creating a calendar item for meeting invitations is as follows:

Public void createcalendarevent ()
{
Calendarservice = new calendarservice ("cnblogsmeeting ");
Calendarservice. setusercredentials ("Google login username", "password ");

Evententry entry = new evententry ();

// Calendar title and content
Entry. Title. Text = "the title of the weekly meeting notification ";
Entry. content. content = "Contents notified by the weekly blog Forum ";

// Start and end time ~
When eventtime = new when (datetime. Now. Date. addhours (17 ),
Datetime. Now. Date. addhours (18 ));
Entry. Times. Add (eventtime );

// Participants to be invited
WHO = new WHO ();
Who. Email = "[email protected]";
Who. rel = "http://schemas.google.com/g/2005#event.attendee ";
Entry. Maid. Add (WHO );

// Send a notification to the invitee
Entry. Communications = true;

// The invitee can modify the calendar item.
Entry. extensionelements. Add (New guestscanmodify ("true "));

Uri posturi = new uri ("ttps: // www.google.com/calendar/feeds/default/private/full ");
Atomentry insertentry = calendarservice. insert (posturi, entry );

Assert. notnull (insertentry );
}

Code download

Googlecalendardemo.rar

Operate Google Calendar with C # code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.