2015-05-14 168 views
0

我使用.net从我的Google联系人中检索联系人信息。但是,它将检索所有包含未存储在“我的联系人”中的已发送电子邮件。无论如何,我只能从我的联系人中检索联系人吗?检索谷歌联系人

下面是代码

 RequestSettings rs = new RequestSettings("", email, password); 
     rs.AutoPaging = true; 
     ContactsRequest cr = new ContactsRequest(rs); 

     Feed<Contact> Contacts = cr.GetContacts(); 

     foreach (Contact contact in Contacts.Entries) 
     { 

      Name name = contact.Name; 
      Response.Write(name.GivenName + " " + name.FamilyName + "<br/>"); 
      foreach (EMail emailId in contact.Emails) 
      { 
       Response.Write(emailId.Address + "<br/>"); 
      } 

      Response.Write("<br/>"); 
     } 
+1

请发表你已经尝试过...我指的是代码 –

+0

代码嵌入 – RoyT

+0

好吧,它有什么问题?根据我的理解,它检索得太多了吗? –

回答

0

进出口使用Google.GData.Contacts从的NuGet V包2.2.0

string redirectUri = "urn:ietf:wg:oauth:2.0:oob"; 

// build the base oauth2 parameters 
var Oauth2Params = new OAuth2Parameters 
{ 
    ClientId = "your google app client id", 
    ClientSecret = "your google app client secret",     
    RedirectUri = redirectUri 
}; 

//security permissions to request from user 
string scopes = "https://www.google.com/m8/feeds/ https://apps-apis.google.com/a/feeds/groups/"; 
Oauth2Params.Scope = scopes; 

string url = OAuthUtil.CreateOAuth2AuthorizationUrl(Oauth2Params); 
//start the default web browser 
System.Diagnostics.Process.Start(url); 
//then type your access code back to the console 
Console.WriteLine("Please paste your Access code after authenticating via browser:"); 
Oauth2Params.AccessCode = Console.ReadLine(); 

OAuthUtil.GetAccessToken(Oauth2Params); 
//store the access token securely somewhere 
//so you dont have to reauthenticate your app at every start 

var reqFactory = new GOAuth2RequestFactory(Oauth2Params.Scope, "your google app name", Oauth2Params); 

string queryUri = "https://www.google.com/m8/feeds/contacts/default/full"; 

ContactsQuery cq = new ContactsQuery(queryUri); 
cq.NumberToRetrieve = 1000; 
//cq.Group = ...group of your desire... 
ContactsService contactService = new ContactsService("your google app name"); 
contactService.RequestFactory = reqFactory; 
ContactsFeed feed = contactService.Query(cq); 
//then foreach feed.Entries   
+0

我在base.Parameter.contactService.Query(cq)上有错误; – RoyT

+0

correct ...我手动测试了这段代码,所以它应该工作 –

+0

为什么在通过浏览器进行身份验证后粘贴访问代码? – RoyT