【问题标题】:Get the Google contacts page by page c#逐页获取谷歌联系人c#
【发布时间】:2020-10-20 15:38:50
【问题描述】:

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

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# pagination google-contacts-api


    【解决方案1】:

    您是否考虑过使用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
         ....
    }
    

    【讨论】:

    • 请在此处直接提供对 OP 有直接帮助的答案(例如,在此处复制和粘贴(和改编)代码)。然后,您还可以添加对另一个网站的引用。这有助于其他有同样问题的人到达这里并查看解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 2015-07-14
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    相关资源
    最近更新 更多