1
/* Copyright (c) 2006 Google Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
15
* Author: Andrew Smith <andy@snae.net> 22/11/08
20
using Google.GData.Contacts;
21
using Google.GData.Client;
22
using Google.GData.Extensions;
23
using Google.GData.Calendar;
30
static void Main(string[] args)
34
// create an OAuth factory to use
35
GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
36
requestFactory.ConsumerKey = "CONSUMER_KEY";
37
requestFactory.ConsumerSecret = "CONSUMER_SECRET";
39
// example of performing a query (use OAuthUri or query.OAuthRequestorId)
40
Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "USER", "DOMAIN");
41
// can use plain Uri if setting OAuthRequestorId in the query
42
// Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");
44
CalendarQuery query = new CalendarQuery();
45
query.Uri = calendarUri;
46
query.OAuthRequestorId = "USER@DOMAIN"; // can do this instead of using OAuthUri for queries
48
CalendarService service = new CalendarService("MyApp");
49
service.RequestFactory = requestFactory;
51
Console.WriteLine("Query Success!");
53
// example with insert (must use OAuthUri)
54
Uri contactsUri = new OAuthUri("http://www.google.com/m8/feeds/contacts/default/full", "USER", "DOMAIN");
56
ContactEntry entry = new ContactEntry();
57
EMail primaryEmail = new EMail("someuser@example.com");
58
primaryEmail.Primary = true;
59
primaryEmail.Rel = ContactsRelationships.IsHome;
60
entry.Emails.Add(primaryEmail);
62
ContactsService contactsService = new ContactsService("MyApp");
63
contactsService.RequestFactory = requestFactory;
64
contactsService.Insert(contactsUri, entry); // this could throw if contact exists
66
Console.WriteLine("Insert Success!");
68
// to perform a batch use
69
// service.Batch(batchFeed, new OAuthUri(atomFeed.Batch, userName, domain));
75
Console.WriteLine("Fail!");
76
Console.WriteLine(ex.Message);
77
Console.WriteLine(ex.StackTrace);