我的问题是我无法在谷歌中添加联系人。我正在使用asp.net 2008。当我使用谷歌日历时,它可以毫无问题地保存。我不确定这是一个象征性的问题还是其他什么,所以我决定在这里问。下面是我添加联系人的代码
protected void Create_Click()
{
GAuthSubRequestFactory authFactory_con = new GAuthSubRequestFactory("cp", "ContactApp");
authFactory_con.Token = (String)Session["token"];
ContactsService ser = new ContactsService(authFactory_con.ApplicationName);
ser.RequestFactory = authFactory_con;
string str = "";
ContactDetail contact = new ContactDetail
{
Name = NameTextBox.Text + " " + LastTextBox.Text,
EmailAddress1 = primaryEmailTextBox.Text,
EmailAddress2 = secondryEmailTextBox.Text,
Phone = phoneTextBox.Text,
Mobile = MobileTextBox.Text,
Street = StreetTextBox.Text,
City = CityTextBox.Text,
Region = RegionTextBox.Text,
PostCode = PostCodeTextBox.Text,
Country = CountryTextBox.Text,
Details = detailsTextBox.Text
};
GoogleContactService.AddContact(contact,ser);
str = "<script>alert('Contact Added Sucessfully')</script>";
Response.Write(str);
}
上面的函数调用了 GoogleContactService 的 AddContact 函数。下面是添加联系人功能的代码
public void AddContact(ContactDetail contact, ContactsService GContactService)
{
ContactEntry newEntry = new ContactEntry();
newEntry.Title.Text = contact.Name;
//newEntry.Name.FullName = contact.Name;
newEntry.Name = new Name();
newEntry.Name.FullName = contact.Name;
EMail primaryEmail = new EMail(contact.EmailAddress1);
primaryEmail.Primary = true;
primaryEmail.Rel = ContactsRelationships.IsWork;
newEntry.Emails.Add(primaryEmail);
EMail secondaryEmail = new EMail(contact.EmailAddress2);
secondaryEmail.Rel = ContactsRelationships.IsHome;
newEntry.Emails.Add(secondaryEmail);
PhoneNumber phoneNumber = new PhoneNumber(contact.Phone);
phoneNumber.Rel = ContactsRelationships.IsHome ;
newEntry.Phonenumbers.Add(phoneNumber);
PhoneNumber phoneNumber_ = new PhoneNumber(contact.Mobile );
phoneNumber_.Primary = true;
phoneNumber_.Rel = ContactsRelationships.IsMobile ;
newEntry.Phonenumbers.Add(phoneNumber_);
newEntry.PostalAddresses.Add(new StructuredPostalAddress()
{
Rel = ContactsRelationships.IsWork,
Primary = true,
Street = contact.Street ,
City = contact.City ,
Region = contact.Region ,
Postcode = contact.PostCode ,
Country = contact.Country ,
FormattedAddress = contact.Street + " , " + contact.City + " , " + contact.Region + " , " + contact.PostCode + " , " + contact.Country,
});
newEntry.Content.Content = contact.Details;
Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
// Uri feedUri = new Uri("http://www.google.com/m8/feeds/contacts/default/full");
System.Net.ServicePointManager.Expect100Continue = false;
ContactEntry createdEntry = (ContactEntry)GContactService.Insert(feedUri, newEntry);
}
我在页面加载时获得令牌
以下是我尝试添加联系人时出现的错误。
用户代码未处理 GDataRequestException 请求执行失败:https//www.google.com/m8/feeds/contacts/default/full