【问题标题】:Google Contacts API not retrieving contactsGoogle Contacts API 未检索联系人
【发布时间】:2013-06-11 07:09:25
【问题描述】:

我正在使用 Google Contacts API 从我的 ASP.NET 应用程序中获取 gmail 联系人。 输入用户名和密码后,应用程序没有响应并且连接超时。 以下是我尝试调试时的错误:

请求执行失败:http://www.google.com/m8/feeds/contacts/default/full

错误快照

【问题讨论】:

  • 任何带有完整源代码示例的最终解决方案?也许在 github 或 codeplex 中

标签: c# asp.net-mvc asp.net-mvc-4 google-contacts-api


【解决方案1】:

请检查您的access_token 是否有效。获取联系人列表作为定义 URL:

https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=" + maxemails + "&oauth_token=access_token";

access_tokenGmail提供,登录成功后。

【讨论】:

    【解决方案2】:

    您确定您的密码和用户是正确的吗? 好吧,我会给你这个代码,它工作正常:


    public DataSet GetGmailContacts(string p_name, string e_id, string psw)
    {
        //p_name = name of your app; e_id = your gmail account; psw = password of your gmail account
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        DataColumn dc1 = new DataColumn();
        dc1.DataType = Type.GetType("System.String");
        dc1.ColumnName = "emailid";
        DataColumn dc2 = new DataColumn();
        dc2.DataType = Type.GetType("System.String");
        dc2.ColumnName = "name";
        dt.Columns.Add(dc1);
        dt.Columns.Add(dc2);
        RequestSettings rs = new RequestSettings(p_name, e_id, psw);
        rs.AutoPaging = true;
        ContactsRequest cr = new ContactsRequest(rs);
        Feed<Contact> f = cr.GetContacts();
        int counter= 0;
        foreach (Contact t in f.Entries)
        {
            Name nombreContacto = t.Name;
            DataRow drx = dt.NewRow();
            drx["emailid"] = t.PrimaryEmail.Address.ToString();
            drx["name"] = t.Title.ToString();
            dt.Rows.Add(drx);
            counter++;
        }
        ds.Tables.Add(dt);
        Response.Write("Total:" + counter.ToString());
        return ds;
    
    }
    

    之后,您可以使用函数返回的数据集填充 Gridview。

    【讨论】:

      猜你喜欢
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多