Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var provider = new FacebookProvider();

            System.Console.WriteLine("Getting token...");
            var token = provider.GetToken();

            System.Console.WriteLine("token:" + token);
            System.Console.WriteLine("Press any key");
            System.Console.ReadKey();
        }
Ejemplo n.º 2
0
        public IHttpActionResult TokenFB()
        {
            string           code       = HttpContext.Current.Request.Params["code"];
            FacebookProvider fbProvider = new FacebookProvider();

            dynamic respone = fbProvider.GetToken(code);

            string   token  = respone.access_token;
            TimeSpan expire = TimeSpan.FromSeconds(Double.Parse(respone.expires_in.ToString()));

            dynamic userDataFB = fbProvider.GetUserData(token);
            string  email      = userDataFB.email;

            List <user> users = _db.user.Where(x => x.mailFB == email).ToList();

            token tokenFB = new token()
            {
                tokenValue = token,
                expire     = DateTime.Now + expire,
                type       = 1,
                active     = true
            };

            if (users.Count == 1)
            {
                tokenFB.userId = users.First().id;

                _db.token.Add(tokenFB);
                _db.SaveChanges();

                return(Ok(token));
            }

            _cache.Add("tokenFB", respone);

            return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Account not connected")));
        }