Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
    User Name:<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    Password:<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Button ID="btnSubmit" Text="Get Gmail Contacts List" runat="server" 
            onclick="btnSubmit_Click" />
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="lblstatus" runat="server"></asp:Label>
    </td>
    <td></td>
    </tr>
    <tr>
    <td colspan="2">
        <asp:GridView ID="GridView1" runat="server" Width="100%">
        </asp:GridView>

    </td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.Contacts;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.Tables.Add("GmailContacts");
        ds.Tables[0].Columns.Add("EmailId");

        RequestSettings rs = new RequestSettings("Idea Elan2", txtUserName.Text, txtPassword.Text);
        rs.AutoPaging = true;

        ContactsRequest cr = new ContactsRequest(rs);

        Feed<Contact> f = cr.GetContacts();

        foreach (Contact contact in f.Entries)
        {
            foreach (EMail email in contact.Emails)
            {
                DataRow row = ds.Tables[0].NewRow();
                row["EmailId"] = email.Address.ToString();
                ds.Tables[0].Rows.Add(row);

            }            
        }

        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        lblstatus.Text = "Total Contacts For" + txtUserName.Text + ":" + ds.Tables[0].Rows.Count.ToString();

        
    }
}


foreach (Contact contact in f.Entries) here it self i am getting error can u please sove this is Issue and the error is Invalid Credentials
Thanks in Advance
Posted
Comments
Which article you are following?
Member 11040036 27-Oct-14 1:15am    
am i Following asp.net suresh article for getting Gmail Contact List

http://www.aspdotnet-suresh.com/2010/04/import-contacts-from-gmail.html

1 solution

Hi,

Try out the solution given on this link.

http://www.aspsnippets.com/Articles/Import-Contacts-from-Google-Gmail-Account-in-ASPNet-using-C-and-VBNet.aspx[^]

Hope this helps !! :) :)

Regards,
Praneet
 
Share this answer
 
Comments
Member 11040036 27-Oct-14 8:17am    
Hai,
Thanks For Replying

But one small problem it giving the Error Of the "The remote server returned an error: (403) Forbidden."
string json = GoogleConnect.Fetch("me", code, 10); the error getting here can u resolve this Error
Thanks in Advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900