Login with Facebook and Google Error: Invalid verification code format

Last Reply one year ago By dharmendr

Posted one year ago

i use your code "login with facebook" and "login with google" but when i use both code on same page it shows error. please help me 

Results 1 - 5 of 6 12
Posted one year ago

Hi sagar@saga,

Please share the error details.


Posted one year ago

I am also looking for similar thing for my site, https://hamarigossip.com

Please let me know what code shall i use.

I am newbie on this, so i will appreciate your help.

Thanks


Posted one year ago

 

///////////THIS IS MY C# CODE ///////////////////////////


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPSnippets.FaceBookAPI;
using System.Web.Script.Serialization;
using ASPSnippets.GoogleAPI;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using System.Web.Script.Services;


public partial class new_registration2 : System.Web.UI.Page
{
    SqlConnection conn, CONN;
    SqlDataReader dr;
    SqlCommand cmd, CMD;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        GoogleConnect.ClientId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            GoogleConnect.ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];

            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                string code = Request.QueryString["code"];
                string json = GoogleConnect.Fetch("me", code);
                GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
                lblId.Text = profile.Id;
                lblName.Text = profile.DisplayName;
                lblEmail.Text = profile.Emails.Find(email => email.Type == "account").Value;
                lblGender.Text = profile.Gender;
                lblType.Text = profile.ObjectType;
                ProfileImage.ImageUrl = profile.Image.Url;
                pnlProfile.Visible = true;
                btnLogin.Enabled = false;

                try
                {
                    string cs = "Data Source=XXXXX;Initial Catalog=XXXXXX;User Id=sa;Password=XXXXXXX;";

                    CONN = new SqlConnection(cs);
                    CMD = new SqlCommand("INSERT INTO Users(Username,Password) VALUES('" + lblId.Text + "','" + lblName.Text + "')", CONN);
                    CMD.Connection = CONN;

                    CONN.Open();
                    CMD.ExecuteNonQuery();
                    CONN.Close();


                    div3.Attributes["class"] = "show";
                    Label15.Text = "Congratulation You Are Succesfully Registered";


                }
                catch (SqlException ee)
                {
                    div3.Attributes["class"] = "show";
                    Label15.Text = ee.Message + "";

                    CONN.Close();
                }
                catch (NullReferenceException w)
                {
                    div3.Attributes["class"] = "show";
                    Label15.Text = w.Message + "";
                    CONN.Close();
                }
                catch (ArgumentException eee)
                {
                    div3.Attributes["class"] = "show";
                    Label15.Text = eee.Message + "";
                }
            
        }
        if (Request.QueryString["error"] == "access_denied")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
        }

        FaceBookConnect.API_Key = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
        FaceBookConnect.API_Secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        if (!IsPostBack)
        {
            if (Request.QueryString["error"] == "access_denied")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
                return;
            }

            string code = Request.QueryString["code"];
            if (!string.IsNullOrEmpty(code))
            {
                string data = FaceBookConnect.Fetch(code, "me?fields=id,name,email");
                FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
                faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
                pnlFaceBookUser.Visible = true;
                Label1.Text = faceBookUser.Id;
                lblUserName.Text = faceBookUser.UserName;
                Label2.Text = faceBookUser.Name;
                Label3.Text = faceBookUser.Email;
                Image1.ImageUrl = faceBookUser.PictureUrl;
                btnLogin.Enabled = false;
            }
        }
    }

    protected void Login(object sender, EventArgs e)
    {
        GoogleConnect.Authorize("profile", "email");
        Label17.Text = "1";
       
    }
    protected void Clear(object sender, EventArgs e)
    {
        GoogleConnect.Clear(Request.QueryString["code"]);
    }
    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 class Email
    {
        public string Value { get; set; }
        public string Type { get; set; }
    }

    public class Image
    {
        public string Url { 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; }
    }
    protected void Login2(object sender, EventArgs e)
    {
        FaceBookConnect.Authorize("user_photos,email", Request.Url.AbsoluteUri.Split('?')[0]);
    }

}

when i envoke "login2" that is "login with facebook" it gives error on line

Line 32:                 string json = GoogleConnect.Fetch("me", code);

saying:

Cannot convert object of type 'System.String' to type '?2?.?3?.?5?'

and when i envoke "login" that is "login with google" it give error on line

Line 99:                 string data = FaceBookConnect.Fetch(code, "me?fields=id,name,email");

saying: 

Code: 100 Message: Invalid verification code format.

But when i use both code that is "login with google"  and  "login with facebook" on different page it works fine and on same page it provides error 

will i have to give html code?

Please help me

 


Posted one year ago

Hi sagar@saga,

You cannot use both the code in same page. Comment one and try and let us know.


Posted one year ago

By commenting one it works fine, but in many sites there is option for both "sign up with google" and "sign up with facebook" i wonder how?