First you need to get ClientID and ClientSecret, for that refer
Google Developer Console: Generate Client ID and Client Secret for use with Google APIs
Then you need to download the ASPSnippets.GoogleAPI DLL using the download link
Download
Finally you need to use the following code
HTML
<asp:Button ID="btnLogin" Text="Login" runat="server" OnClick="Login" />
<asp:Panel ID="pnlProfile" runat="server" Visible="false">
<hr />
<asp:DataList ID="dlFiles" runat="server">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" class="table">
<tr>
<th colspan="2">
<%# Eval("Title") %>
</th>
</tr>
<tr>
<td rowspan="6" style="width: 100px">
<a href='<%# Eval("ThumbnailLink") %>' target="_blank">
<img alt="" src='<%# Eval("ThumbnailLink") %>' class="thumbnail" />
</a>
</td>
<tr>
<td style="width: 200px">
<b>File Name:</b>
<%# Eval("OriginalFileName") %>
</td>
</tr>
<tr>
<td>
<b>Created Date:</b>
<%# Convert.ToDateTime(Eval("CreatedDate")).ToString("dd, MMM yyyy") %>
</td>
</tr>
<tr>
<td>
<b>Modified Date:</b>
<%# Convert.ToDateTime(Eval("ModifiedDate")).ToString("dd, MMM yyyy") %>
</td>
</tr>
<tr>
<td>
<b>File Type:</b>
<img alt="" src='<%# Eval("IconLink") %>' />
</td>
</tr>
<tr>
<td>
<a href='<%# Eval("WebContentLink") %>'>Download File</a>
</td>
</tr>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</asp:Panel>
Code
protected void Page_Load(object sender, EventArgs e)
{
GoogleConnect.ClientId = "<Google ClientID>";
GoogleConnect.ClientSecret = "<Google ClientSecret>";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
GoogleConnect.API = EnumAPI.Drive;
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"];
string json = GoogleConnect.Fetch("me", code);
GoogleDriveFiles files = new JavaScriptSerializer().Deserialize<GoogleDriveFiles>(json);
dlFiles.DataSource = files;
dlFiles.DataBind();
pnlProfile.Visible = true;
btnLogin.Enabled = false;
}
if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
}
protected void Login(object sender, EventArgs e)
{
GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.readonly");
}
protected void Clear(object sender, EventArgs e)
{
GoogleConnect.Clear();
}
public class GoogleDriveFiles
{
public List<GoogleDriveFile> Items { get; set; }
}
public class GoogleDriveFile
{
public string Id { get; set; }
public string Title { get; set; }
public string OriginalFilename { get; set; }
public string ThumbnailLink { get; set; }
public string IconLink { get; set; }
public string WebContentLink { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public GoogleDriveFileLabel Labels { get; set; }
}
public class GoogleDriveFileLabel
{
public bool Starred { get; set; }
public bool Hidden { get; set; }
public bool Trashed { get; set; }
public bool Restricted { get; set; }
public bool Viewed { get; set; }
}
Screenshot
