首页 > 解决方案 > 逐页获取谷歌联系人c#

问题描述

我开发了应用程序来阅读谷歌联系人。我可以阅读联系人,但我不确定如何逐页进行。在这里,我附上了我的示例代码。

GoogleCredential credential = GoogleCredential.FromJson(gCredJson)
                    .CreateScoped(Scopes)
                    .CreateWithUser(usrName);

string token = await credential.UnderlyingCredential.GetAccessTokenForRequestAsync().ConfigureAwait(true);

获取联系人

OAuth2Parameters parameters = new OAuth2Parameters();
parameters.AccessToken = token;

RequestSettings settings = new RequestSettings("mailApp", parameters);
settings.AutoPaging = true;
settings.Maximum = 2;
settings.PageSize = 2;
ContactsRequest cr = new ContactsRequest(settings);
Feed<Contact> f = cr.GetContacts("myemail@gmail.com");
foreach (Contact c in f.Entries)
{
    Console.WriteLine(c.Name.FullName);
}

上面的代码给了我联系方式。但是,我不知道如何处理下一页。任何人对此提供帮助将不胜感激。

标签: c#paginationgoogle-contacts-api

解决方案


您是否考虑过使用ContactsQuery?请检查示例 #2。

var contactsPerQuery = 50;
var maxTotal = 32000;
ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
query.NumberToRetrieve = contactsPerQuery;

for (int index = 0; index < maxTotal; index += contactsPerQuery)
{
     query.StartIndex = index;
     Feed<Contact> feed = cr.Get<Contact>(query);
     
     //display contacts from feed.Entries
     ....
}

推荐阅读