コード例 #1
0
        private void CreateContact(ContactsRequest cr, Contact contact)
        {
            var newEntry = new global::Google.Contacts.Contact
            {
                Name = new Name()
                {
                    FullName   = contact.FirstName + contact.LastName,
                    GivenName  = contact.FirstName,
                    FamilyName = contact.LastName,
                }
            };

            // Set the contact's name.

            // Set the contact's e-mail addresses.
            newEntry.Emails.Add(new EMail()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsHome,
                Address = contact.EmailAddress
            });
            // Set the contact's phone numbers.
            newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Primary = true,
                Rel     = ContactsRelationships.IsWork,
                Value   = contact.PhoneNumber
            });
            // Insert the contact.
            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

            global::Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry);
            //return createdEntry;
        }
コード例 #2
0
        private Contact CastToGoferContact(global::Google.Contacts.Contact gContact, ContactsRequest contactReq)
        {
            if (gContact.Id == null)
            {
                throw new Exception("No Id, Invalid Google contact");
            }

            // This is the unique id given by Google. URL format
            var id        = gContact.Id;
            var firstName = gContact.Name.GivenName;
            var lastName  = gContact.Name.FamilyName ?? gContact.Name.GivenName;
            var username  = gContact.Name.FullName;
            var email     = gContact.Emails.FirstOrDefault() != null ? gContact.PrimaryEmail.Address : "";

            var birthdate = gContact.Updated.ToString("dd/MM/yyyy");
            var phone     = gContact.Phonenumbers.FirstOrDefault() != null?CreatePhoneNumber(gContact.Phonenumbers.FirstOrDefault()) : "";

            var photo = GetContactPhoto(gContact.PhotoUri, contactReq);

            return(new Contact(firstName, lastName, username, email, birthdate, phone, "", photo, id));
        }