【问题标题】:Retrieve google contact检索谷歌联系人
【发布时间】:2015-05-14 19:25:34
【问题描述】:

我正在使用 .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/>");
        }

【问题讨论】:

  • 我只需要从“我的联系人”中检索联系人
  • 您是如何指定 RequestSettings 的?我不明白它需要什么参数来发送请求以及我应该从哪里获取这些参数。

标签: c# api contact


【解决方案1】:

我正在使用来自 nuget v 2.2.0 的 Google.GData.Contacts 包

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         

【讨论】:

  • 我在base.Parameter.contactService.Query(cq)上有一个错误;
  • 浏览器认证后为什么要粘贴访问码?
  • 你在测试什么样的环境?我正在使用 c# .net
  • 无论如何要在网络表单上实现这一点?
猜你喜欢
  • 1970-01-01
  • 2012-08-03
  • 1970-01-01
  • 1970-01-01
  • 2014-02-09
  • 2013-11-03
  • 1970-01-01
  • 1970-01-01
  • 2017-05-11
相关资源
最近更新 更多