Default.aspx
<div>
<a href="#" class="button" id="A1" onclick="OpenGoogleLoginPopup();" name="butrequest">
<span>Login with google</span></a>
<br />
Google ID : <%=Google_ID%> <br />
Email/user name : <%=Email_address%> <br />
first name : <%=firstName%> <br />
Last name : <%=LastName%> <br />
</div>
<script type="text/javascript" language="javascript">
function OpenGoogleLoginPopup() {
var url = "https://accounts.google.com/o/oauth2/auth?";
url += "scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email&";
url += "state=%2Fprofile&"
url += "redirect_uri=<%=Return_url %>&"
url += "response_type=token&"
url += "client_id=<%=Client_ID %>";
window.location = url;
}
</script> Default.aspx.cs
public string Email_address = "";
public string Google_ID = "";
public string firstName = "";
public string LastName = "";
public string Client_ID = "";
public string Return_url = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Client_ID = "Your Client ID";
Return_url = "Your Redirected URL";
}
if (Request.QueryString["access_token"] != null)
{
String URI = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + Request.QueryString["access_token"].ToString();
WebClient webClient = new WebClient();
Stream stream = webClient.OpenRead(URI);
string b;
using (StreamReader br = new StreamReader(stream))
{
b = br.ReadToEnd();
}
b = b.Replace("id", "").Replace("email", "");
b = b.Replace("given_name", "");
b = b.Replace("family_name", "").Replace("link", "").Replace("picture", "");
b = b.Replace("gender", "").Replace("locale", "").Replace(":", "");
b = b.Replace("\"", "").Replace("name", "").Replace("{", "").Replace("}", "");
Array ar = b.Split(",".ToCharArray());
for (int p = 0; p < ar.Length; p++)
{
ar.SetValue(ar.GetValue(p).ToString().Trim(), p);
}
Email_address = ar.GetValue(1).ToString();
Google_ID = ar.GetValue(0).ToString();
firstName = ar.GetValue(4).ToString();
LastName = ar.GetValue(5).ToString();
}
}