Пример #1
0
        public static bool ValidateFacebookId(ref string username, string facebookId)
        {
            string apiKey    = ConfigurationManager.AppSettings["FacebookAPIKey"] as string;
            string apiSecret = ConfigurationManager.AppSettings["FacebookApplicationSecret"] as string;

            FBConnectAuthentication auth = new FBConnectAuthentication(apiKey, apiSecret);

            if (auth.Validate() == ValidationState.Valid)
            {
                FBConnectSession fbSession = auth.GetSession();
                string           userId    = fbSession.UserID;

                AppUserRepository userRepository = new AppUserRepository();
                AppUser           user           = userRepository.GetByFacebookId(userId);

                if (null != user)
                {
                    username = user.UserName;
                    return(true);
                }
            }
            return(false);
        }
    protected void btn_Go_Click(object sender, EventArgs e)
    {
        _connectSession = new ConnectSession(APPLICATION_KEY, SECRET_KEY);

        FBConnectAuthentication auth = new FBConnectAuthentication("148883595138929", "94da7bd77167c18aa7b075d87f445cf9"); //Note this is the "app id", not "api Key"
        if (auth.Validate() != ValidationState.Valid)
        {
            // The request does not contain the details of a valid Facebook connect session -
            // you'll probably want to throw an error here.
            this.lbl_currentStatus.Text = "Error";

        }
        else
        {
            FBConnectSession fbSession = auth.GetSession();
            string userId = fbSession.UserID;
            string sessionKey = fbSession.SessionKey;
            string accessToken = fbSession.AccessToken; //This is the Graph API access token (available only when using the Graph API)
            // These values can now be used to communicate with Facebook on behalf of your user - perhaps using the Facebook Developer Toolkit
            // The expiry time and session secret is also available.
            this.lbl_currentStatus.Text = accessToken;

           /* if (!_connectSession.IsConnected())
            {
                this.lbl_currentStatus.Text = "Usuario no conectado";
            }
            else
            {
                _facebookAPI = new Api(_connectSession);

                user user = _facebookAPI.Users.GetInfo();

                this.lbl_user.Text = string.Format("{0} {1}", user.first_name, user.last_name);

            }*/

            if (userId == "639765435")
            {
                lbl_user.Text = "Hector Fernando Sabillon";
            }
            else if (userId == "894045382")
            {
                lbl_user.Text = "Ricardo Escobar";
            }
            else if(userId == "1037870586")
            {
                lbl_user.Text = "Uchiha Sama";
            }
            else if (userId == "549886672")
            {
                lbl_user.Text = "Alexis Castillo";
            }
            else if (userId == "553699803")
            {
                lbl_user.Text = "Rogger Vasquez";
            }
            else
            {
                lbl_user.Text = userId;
            }

        }

        if (lbl_currentStatus.Text != "Error" && lbl_currentStatus.Text!="No estas conectado")
        {
            tbx_pub.Visible = true;
            btn_Publicar.Visible = true;
            btn_OtroDia.Visible = true;
            lbl_currentStatus.Text = "Conectado";
        }
    }