【问题标题】:Get Google contacts via AuthSub c#通过 AuthSub c# 获取 Google 联系人
【发布时间】:2011-04-15 14:12:26
【问题描述】:

有没有人有一个在 c# 中通过 AuthSub 获取 google 联系人的工作示例

我已经尝试过这个url,但我无法完成它。

【问题讨论】:

    标签: c# google-contacts-api authsub


    【解决方案1】:

    这是我的一个项目中的一段代码:

        public class GoogleContactsProvider : IContactProvider
    {
        #region IContactProvider Members
    
        /// <summary>
        /// Gets the contacts list form the contact provider.
        /// </summary>
        /// <returns></returns>
        public EntityCollection<IContactItem> GetContactsList()
        {
            EntityCollection<IContactItem> collection = new EntityCollection<IContactItem>();
    
            // Setup the contacts request (autopage true returns all contacts)
            RequestSettings requestSettings = new RequestSettings("AgileMe", UserName, Password);
            requestSettings.AutoPaging = true;
            ContactsRequest contactsRequest = new ContactsRequest(requestSettings);
    
            // Get the feed
            Feed<Contact> feed = contactsRequest.GetContacts();
    
            // create our collection by looping through the feed
            foreach (Contact contact in feed.Entries)
            {
                GoogleContactItem newContact = new GoogleContactItem();
                newContact.Name = contact.PrimaryEmail.Address;
                newContact.Summary = contact.Summary;
    
                collection.Add(newContact);
            }
    
            return collection;
        }
    
        /// <summary>
        /// Gets or sets the name of the user for the contact provider.
        /// </summary>
        /// <value>The name of the user.</value>
        public string UserName { get; set; }
    
        /// <summary>
        /// Gets or sets the password for the contact provider.
        /// </summary>
        /// <value>The password.</value>
        public string Password { get; set; }
    
        #endregion
    }
    

    EntityCollection 是一个简单列表的包装器,而 GoogleContactItem 是一个检索信息的包装器。

    【讨论】:

    • @Perry,我正在尝试与 stackoverflow 登录类似的登录,在那里我将被重定向到 gmail 以输入密码,但这里我用于获取通讯簿。谢谢
    • 嘿,我不确定这是您的答案还是您尝试做其他事情?你能进一步解释一下吗?
    • 什么是 GoogleContactItem、IContactProvider、..?
    【解决方案2】:

    我发现这个例子很简单。 link 而且效果很好。

    【讨论】:

    • OAuth 1.0 已弃用?任何使用 OAuth 2.0 的新示例?
    猜你喜欢
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多