C# 如何使用谷歌联系人创建和更新gmail群组
我有以下标准:- 1.使用sql db中的查询执行创建gmail组。此查询将根据地区筛选联系人 2.对于每个发送请求,这些联系人可能不同,也可能不不同。它取决于发送时处于活动状态的用户 3.我能够向团队发送邮件 主要问题是如何在每次向组成员(不包括非活动成员)发送邮件之前更新组 如果你需要更多的解释,请告诉我。我会尽力的 更新: 我在控制台应用程序中完成了以下代码:C# 如何使用谷歌联系人创建和更新gmail群组,c#,gdata-api,google-contacts-api,C#,Gdata Api,Google Contacts Api,我有以下标准:- 1.使用sql db中的查询执行创建gmail组。此查询将根据地区筛选联系人 2.对于每个发送请求,这些联系人可能不同,也可能不不同。它取决于发送时处于活动状态的用户 3.我能够向团队发送邮件 主要问题是如何在每次向组成员(不包括非活动成员)发送邮件之前更新组 如果你需要更多的解释,请告诉我。我会尽力的 更新: 我在控制台应用程序中完成了以下代码: using System; using System.Collections.Generic; using System.Linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Contacts;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
namespace IMAPCommands
{
class Program
{
static void Main(string[] args)
{ GoogleContactService.InitializeService("mailid", "password");
List<ContactDetail> test = GoogleContactService.GetContacts("System Group: My Contacts");
//Use break point here
Console.ReadLine();
}
public class GoogleContactService
{
#region Properties
public static ContactsService GContactService = null;
#endregion
#region Methods
public static void InitializeService(string username, string password)
{
GContactService = new ContactsService("Contact Infomation");
GContactService.setUserCredentials(username, password);
}
public static List<ContactDetail> GetContacts(string GroupName = null)
{
List<ContactDetail> contactDetails = new List<ContactDetail>();
ContactsQuery contactQuery = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
contactQuery.NumberToRetrieve = 1000;
if (!String.IsNullOrEmpty(GroupName))
{
GroupEntry ge = GetGroup(GroupName);
if (ge != null)
contactQuery.Group = ge.Id.AbsoluteUri;
}
else
{
string groupName = "";
GroupEntry ge = GetGroup(groupName);
if (ge != null)
contactQuery.Group = ge.Id.AbsoluteUri;
}
ContactsFeed feed = GContactService.Query(contactQuery);
foreach (ContactEntry entry in feed.Entries)
{
if (entry.Title.Text == "TechnicalBulletinName")
{
int test = entry.Emails.Count;
ContactDetail contact = new ContactDetail
{
Name = entry.Title.Text,
EmailAddress1 = entry.Emails.Count >= 1 ? entry.Emails[0].Address : "",
EmailAddress2 = entry.Emails.Count >= 2 ? entry.Emails[1].Address : "",
Phone1 = entry.Phonenumbers.Count >= 1 ? entry.Phonenumbers[0].Value : "",
Phone2 = entry.Phonenumbers.Count >= 2 ? entry.Phonenumbers[1].Value : "",
Address = entry.PostalAddresses.Count >= 1 ? entry.PostalAddresses[0].FormattedAddress : "",
Details = entry.Content.Content
};
contact.UserDefinedFields = new List<UDT>();
foreach (var udt in entry.UserDefinedFields)
{
contact.UserDefinedFields.Add(new UDT { Key = udt.Key, Value = udt.Value });
}
contactDetails.Add(contact);
}
}
return contactDetails;
}
#endregion
#region Helpers
public static GroupEntry GetGroup(string GroupName)
{
GroupEntry groupEntry = null;
GroupsQuery groupQuery = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));
groupQuery.NumberToRetrieve = 100;
GroupsFeed groupFeed = GContactService.Query(groupQuery);
foreach (GroupEntry entry in groupFeed.Entries)
{
if (entry.Title.Text.Equals(GroupName, StringComparison.CurrentCultureIgnoreCase))
{
groupEntry = entry;
break;
}
}
return groupEntry;
}
#endregion
}
public class ContactDetail
{
public string Name { get; set; }
public string EmailAddress1 { get; set; }
public string EmailAddress2 { get; set; }
public string Phone1 { get; set; }
public string Phone2 { get; set; }
public string Address { get; set; }
public string Details { get; set; }
public string Pipe { get; set; }
public string Relationship { get; set; }
public string Status { get; set; }
public List<UDT> UserDefinedFields { get; set; }
}
public class UDT
{
public string Key { get; set; }
public string Value { get; set; }
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用Google.Contacts;
使用Google.GData.Contacts;
使用Google.GData.Client;
使用Google.GData.Extensions;
名称空间IMAPCommands
{
班级计划
{
静态void Main(字符串[]参数)
{GoogleContactService.InitializeService(“mailid”,“password”);
列表测试=GoogleContactService.GetContacts(“系统组:我的联系人”);
//在这里使用断点
Console.ReadLine();
}
公共类谷歌通讯服务
{
#区域属性
公共静态联系人服务GContactService=null;
#端区
#区域方法
公共静态void InitializeService(字符串用户名、字符串密码)
{
GContactService=新联系人服务(“联系人信息”);
GContactService.setUserCredentials(用户名、密码);
}
公共静态列表GetContacts(字符串GroupName=null)
{
List contactDetails=新列表();
ContactsQuery contactQuery=新建ContactsQuery(ContactsQuery.CreateContactsUri(“默认”));
contactQuery.NumberToRetrieve=1000;
如果(!String.IsNullOrEmpty(GroupName))
{
GroupEntry ge=GetGroup(GroupName);
如果(ge!=null)
contactQuery.Group=ge.Id.AbsoluteUri;
}
其他的
{
字符串groupName=“”;
GroupEntry ge=GetGroup(groupName);
如果(ge!=null)
contactQuery.Group=ge.Id.AbsoluteUri;
}
ContactsFeed feed=GContactService.Query(contactQuery);
foreach(feed.Entries中的ContactEntry)
{
如果(entry.Title.Text==“TechnicalBulletinName”)
{
int test=entry.Emails.Count;
ContactDetail联系人=新的ContactDetail
{
Name=entry.Title.Text,
EmailAddress1=entry.Emails.Count>=1?entry.Emails[0]。地址:“”,
EmailAddress2=entry.Emails.Count>=2?entry.Emails[1]。地址:“”,
Phone1=entry.Phonenumbers.Count>=1?entry.Phonenumbers[0]。值:“”,
Phone2=entry.PhoneNumber.Count>=2?entry.PhoneNumber[1]。值:“”,
Address=entry.PostalAddresses.Count>=1?entry.PostalAddresses[0]。格式化地址:“”,
详细信息=entry.Content.Content
};
contact.UserDefinedFields=新列表();
foreach(entry.UserDefinedFields中的var udt)
{
contact.UserDefinedFields.Add(newudt{Key=UDT.Key,Value=UDT.Value});
}
联系人详细信息。添加(联系人);
}
}
返回联系人详细信息;
}
#端区
#地区助手
公共静态GroupEntry GetGroup(字符串GroupName)
{
GroupEntry-GroupEntry=null;
GroupsQuery groupQuery=newgroupsquery(GroupsQuery.CreateGroupsUri(“默认”));
groupQuery.numbertorRetrieve=100;
GroupsFeed groupFeed=GContactService.Query(groupQuery);
foreach(groupFeed.Entries中的GroupEntry条目)
{
if(entry.Title.Text.Equals(GroupName、StringComparison.CurrentCultureIgnoreCase))
{
groupEntry=entry;
打破
}
}
返回分组条目;
}
#端区
}
公共类联系人详细信息
{
公共字符串名称{get;set;}
公共字符串EmailAddress1{get;set;}
公共字符串EmailAddress2{get;set;}
公共字符串Phone1{get;set;}
公共字符串Phone2{get;set;}
公共字符串地址{get;set;}
公共字符串详细信息{get;set;}
公共字符串管道{get;set;}
公共字符串关系{get;set;}
公共字符串状态{get;set;}
公共列表UserDefinedFields{get;set;}
}
公共类UDT
{
公共字符串密钥{get;set;}
公共字符串值{get;set;}
}
}
仍然无法获取属于组成员的联系人列表Technical BulletinName。我只能获取此组的emailID,而不是组成员