I am working on asp.net application where i am using facebook and google plus login with c sharp code. Everything working fine for both social platforms. I am using the following code:
CS:
GoogleProfile profile = new GoogleProfile();
FaceBookUser faceBookUser = new FaceBookUser();
protected void Page_Load(object sender, EventArgs e)
{
try
{
//Google plus
GoogleCoect.ClientId = ConfigurationManager.AppSettings["GoogleClientId"].ToString();
GoogleCoect.ClientSecret = ConfigurationManager.AppSettings["GoogleClientSecret"].ToString();
//Facebook
FaceBookCoect.API_Key = ConfigurationManager.AppSettings["FacebookAPIKey"].ToString();
FaceBookCoect.API_Secret = ConfigurationManager.AppSettings["FacebookAPISecret"].ToString();
if (!IsPostBack)
{
if (Session["checkValue"].ToString().Contains("Google"))
{
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
//GoogleProfile profile = new GoogleProfile();
string code = Request.QueryString["code"];
string json = GoogleCoect.Fetch("me", code);
profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
if (Request.QueryString["error"] == "access_denied")
{
//ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
}
else
{
if (Request.QueryString["error"] == "access_denied")
{
//ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
//retu;
}
// FaceBookUser faceBookUser = new FaceBookUser();
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
string data = FaceBookCoect.Fetch(code, "me");
faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
}
else
{
Login(GetDataFromService.GetFacebookUserName(hdnApiId.Value), "", hdnApiId.Value);
}
}
}
}
}
}
catch (Exception ex)
{
base.LogError(ex, "Server Not Responding");
}
}
Google and facebook signup button events:
protected void btnGoogleSignUp_Click(object sender, EventArgs e)
{
Session["checkValue"] = "Google";
GoogleCoect.RedirectUri = ConfigurationManager.AppSettings["RedirectSignUpUrl"].ToString();// Request.Url.AbsoluteUri.Split('?')[0];
GoogleCoect.Authorize("profile", "email");
}
protected void btnFacebookSignUp_Click(object sender, EventArgs e)
{
Session["checkValue"] = "Facebook";
FaceBookCoect.Authorize("user_photos,email,user_location,
user_birthday", ConfigurationManager.AppSettings["RedirectSignUpUrl"].ToString());
}
Class:
public class GoogleProfile
{
public string Id { get; set; }
public string DisplayName { get; set; }
public Image Image { get; set; }
public List<Email> Emails { get; set; }
public string Gender { get; set; }
public string ObjectType { get; set; }
public name Name { get; set; }
}
public class Email
{
public string Value { get; set; }
public string Type { get; set; }
}
public class Image
{
public string Url { get; set; }
}
public class name
{
public string familyName { get; set; }
public string givenName { get; set; }
}
public class FaceBookUser
{
public string Id { get; set; }
public string Name { get; set; }
public string UserName { get; set; }
public string PictureUrl { get; set; }
public string Email { get; set; }
}
Problem:
Sometimes when i am going for facebook login after google login i am getting google api code instead of facebook api code. How i can resolve this issue may be this is coming due to caching. Thanks in advance. If you need more info i will try my best to explain in more detail.
