2015-05-14 208 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