예제 #1
0
 /// <summary>
 /// Revoke facebook connection
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public bool RevokeFacebookConnection(int uid)
 {
     try
     {
         var user         = userRepository.FindBy(uid);
         var accessToken  = user.FacebookAccessToken;
         var clientId     = user.Account.FacebookAPPID;
         var clientSecret = user.Account.FacebookAPPSecret;
         if (string.IsNullOrEmpty(accessToken))
         {
             throw new Exception("Access token is empty for user " + uid);
         }
         accessToken = GetExtendedFacebookAccessToken(accessToken, clientId, clientSecret);
         userRepository.UpdateFacebookAccessToken(uid, accessToken);
         var fb = new FacebookClient(accessToken);
         fb.AppId     = clientId;
         fb.AppSecret = clientSecret;
         var fbValues = (IDictionary <string, object>)fb.Get("me");
         return((bool)fb.Delete(fbValues["id"].ToString()));
     }
     catch (Exception ex)
     {
         Logger.Current.Error("Error while revoking access to the user " + uid, ex);
     }
     return(false);
 }
 public dynamic DeleteTest(string accessToken, string path)
 {
     return Test("delete test", () =>
                                    {
                                        var fb = new FacebookClient(accessToken);
                                        return fb.Delete(path);
                                    });
 }
예제 #3
0
 public dynamic DeleteTest(string accessToken, string path)
 {
     return(Test("delete test", () =>
     {
         var fb = new FacebookClient(accessToken);
         return fb.Delete(path);
     }));
 }
예제 #4
0
 private static bool ConsoleEventCallback(int eventType)
 {
     if (eventType == 2 || eventType == 0) //2 is user perform exit, 0 is application interupt (^C)
     {
         MainEvent.Reset();
         Console.ForegroundColor = ConsoleColor.White;
         Console.BackgroundColor = ConsoleColor.Black;
         Console.Write("\n\n\nResources cleaning...");
         FacebookHelper.DeletePreviousPost(ref fbClient, post => { if (post.Message.Contains("Apple Music"))
                                                                   {
                                                                       fbClient.Delete(post.Id);
                                                                   }
                                           });
         Console.Clear();
         Environment.Exit(0);
     }
     return(false);
 }
예제 #5
0
        public bool RevokePermission(FacebookClient fb)
        {
            var res = fb.Delete("me/permissions");

            if (res is bool && (bool)res == true)
            {
                return((bool)res);
            }
            return(false);
        }
예제 #6
0
 public void DeleteAction(string actionId)
 {
     if (!string.IsNullOrEmpty(actionId))
     {
         Task.Factory.StartNew(() =>
         {
             var client = new FacebookClient(AccessToken);
             client.Delete(string.Format("{0}", actionId));
         });
     }
 }
 public bool DeletePost(string post_id)
 {
     try
     {
         dynamic result = fb.Delete(post_id);
         return(result.sucess);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #8
0
 public void Delete(string pageId, string realPostId)
 {
     try
     {
         InitializeFacebookClient();
         _fbClient.Delete(String.Format("/{0}_{1}", pageId, realPostId));
     }
     catch (FacebookOAuthException)
     {
     }
     catch (Exception)
     {
     }
 }
예제 #9
0
 public static bool DeleteUser(string id, string accessToken)
 {
     try {
         var     fb     = new FacebookClient();
         dynamic result = fb.Delete(id, new{
             access_token = accessToken
         });
         return(true);
     }
     catch (Exception) {
         ;
     }
     return(false);
 }
        private void deletePermissions()
        {
            try
            {
                var fb  = new FacebookClient(m_LoginResult.AccessToken);
                var res = fb.Delete("me/permissions");
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format(
                                    @"Error detected while trying delete permissions !
reason: {0}",
                                    e.Message));
            }
        }
        // [TestCategory("RequiresOAuth")]
        public void Wall_Post_Publish_And_Delete()
        {
            FacebookClient app = new FacebookClient();
            dynamic parameters = new ExpandoObject();
            parameters.access_token = ConfigurationManager.AppSettings["AccessToken"];
            parameters.message = "This is a test message that has been published by the Facebook C# SDK on Codeplex. " + DateTime.UtcNow.Ticks.ToString();

            dynamic result = app.Post("/me/feed", parameters);

            Assert.NotEqual(null, result.id);

            // Delete methods should return 'true'
            var isDeleted = app.Delete(result.id);

            Assert.True(isDeleted);
        }
예제 #12
0
        // [TestCategory("RequiresOAuth")]
        public void Wall_Post_Publish_And_Delete()
        {
            FacebookClient app        = new FacebookClient();
            dynamic        parameters = new ExpandoObject();

            parameters.access_token = ConfigurationManager.AppSettings["AccessToken"];
            parameters.message      = "This is a test message that has been published by the Facebook C# SDK on Codeplex. " + DateTime.UtcNow.Ticks.ToString();

            dynamic result = app.Post("/me/feed", parameters);

            Assert.NotEqual(null, result.id);

            // Delete methods should return 'true'
            var isDeleted = app.Delete(result.id);

            Assert.True(isDeleted);
        }
예제 #13
0
        public static void Delete(string accessToken, string id)
        {
            try
            {
                var fb = new FacebookClient(accessToken);

                var result = fb.Delete(id);

                // Note: This json result is not the original json string as returned by Facebook.
                Console.WriteLine("Json: {0}", result.ToString());
            }
            catch (FacebookApiException)
            {
                // Note: make sure to handle this exception.
                throw;
            }
        }
        /// <summary>
        /// Deletes the facebook post.
        /// </summary>
        /// <param name="pageAccessToken">The page access token.</param>
        /// <param name="pageid">The pageid.</param>
        /// <param name="facebookParameters">The facebook parameters.</param>
        public void DeleteFacebookPost(string pageAccessToken, string pageid,
                                       Dictionary <string, object> facebookParameters)
        {
            var fbClient = new FacebookClient(pageAccessToken);

            fbClient.AppId     = AppId;
            fbClient.AppSecret = AppSecret;

            var publishedResponse = fbClient.Delete($"/{pageid}", facebookParameters);

            if (publishedResponse != null)
            {
                if (typeof(JsonObject) == publishedResponse.GetType())
                {
                    var respJsonObject = (JsonObject)publishedResponse;
                    ResponseJsonObject = respJsonObject;
                }
            }
        }
예제 #15
0
        public int deleteComment(string commentID, string postID)
        {
            try
            {
                client.Delete(commentID);
                return(0);
            }
            catch (FacebookApiException ex)
            {
                if (ex.ErrorCode == 100) //postId does not exist
                {
                    Proposal proposal = _db.Proposal.FirstOrDefault(c => c.FacebookPostId == postID);
                    proposal.FacebookPostId = "";
                    _db.SaveChanges();
                    return(1);
                }
                if (ex.ErrorCode == 190) //Token Expired
                {
                    return(2);
                }

                return(3);//another error has happenned
            }
        }
예제 #16
0
        public async Task <HttpResponseMessage> SignOut()
        {
            try {
                var user = await users.FindByNameAsync(User.Identity.Name);

                if (user != null)
                {
                    try
                    {
                        var client = new FacebookClient(user.FacebookToken);
                        Facebook.JsonObject response = (Facebook.JsonObject)client.Delete("/me/permissions");
                    } catch (Exception ex)
                    {
                        // null
                    }
                }
                AuthenticationManager.SignOut();
                var account = new UserDetail();
                account.isAuthenticated = false;
                return(Request.CreateResponse(account));
            } catch (Exception ex) {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
예제 #17
0
        // **************************************
        // URL: /Account/LogOn
        // **************************************

        public ActionResult LogOn(string ReturnUrl)
        {
            if (FacebookWebContext.Current.IsAuthenticated() && FacebookWebContext.Current.IsAuthorized())
            {
                FacebookClient fbClient   = new FacebookClient(FacebookWebContext.Current.AccessToken);
                dynamic        me         = fbClient.Get("me");
                string         facebookId = (string)me.id;
                string         userEmail  = (string)me.email;

                if (facebookId == null || userEmail == null)
                {
                    throw new FacebookOAuthException();
                }

                var user = market.Users.SingleOrDefault(u => u.Email == userEmail);

                if (user == null)
                {
                    //User does not exist in our DB, let us kick him out
                    var model = new LogOnModel();
                    ModelState.AddModelError("", "Oops! Looks like you have not yet registered for an account.");
                    fbClient.Delete(facebookId + "/permissions");
                    FormsAuthentication.SignOut();
                    //fbClient.Delete(Url.Action("LogOn", "Account", null, Request.Url.Scheme, Request.Url.Host));
                    return(View(model));
                }

                var fbUser = market.FacebookUsers.SingleOrDefault(f => f.Id == facebookId);

                if (fbUser == null)
                {
                    MembershipUser RegisteredUser = Membership.GetUser(user.Email.ToLower());

                    if (RegisteredUser != null)
                    {
                        if (!RegisteredUser.IsApproved)
                        {
                            //User is in our DB but has already requested access and is pending approval. Let us kick him out.
                            var model = new LogOnModel();
                            ModelState.AddModelError("", "Sorry, your account has not yet been activated. Stay tuned, we're almost ready for you.");
                            fbClient.Delete(facebookId + "/permissions");
                            FormsAuthentication.SignOut();
                            return(View(model));
                        }
                    }

                    var location = me.location;
                    if (location == null)
                    {
                        location = me.hometown;
                        if (location == null)
                        {
                            return(View());
                        }
                    }
                    string[] address = ((string)location.name).Split(',');
                    string   city    = address[0].Trim();
                    string   prov    = address[1].Trim();

                    //Now creating the facebook user profile. We can wire this to the regular user by using a foreign key
                    market.FacebookUsers.Add(new FacebookUser
                    {
                        Id             = facebookId,
                        UserModelEmail = (string)me.email,
                        AccessToken    = FacebookWebContext.Current.AccessToken,
                        IsApproved     = true,
                        Expires        = FacebookWebContext.Current.Session.Expires
                    });
                    log.Info("Account - Creating new Facebook user (" + (string)me.first_name + " " + (string)me.last_name + ")");
                    market.SaveChanges();
                }
                else
                {
                    if (!fbUser.IsApproved)
                    {
                        //User has requested access previously using facebook and is pending approval. Let us kick him out.
                        var model = new LogOnModel();
                        ModelState.AddModelError("", "Sorry, your account has not yet been activated. Stay tuned, we're almost ready for you.");
                        fbClient.Delete(facebookId + "/permissions");
                        FormsAuthentication.SignOut();
                        return(View(model));
                    }
                }
                //User is either created or he/she exists. Let us sign them in using email as the username.
                FormsAuthentication.SetAuthCookie((string)me.email, false);
                Session["USER_F_NAME"] = (string)me.first_name;
                log.Info("Account - User logged in (" + (string)me.email + ")");
                if (Url.IsLocalUrl(ReturnUrl))
                {
                    return(Redirect(ReturnUrl));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
예제 #18
0
        // **************************************
        // URL: /Account/Register
        // **************************************

        public ActionResult Register()
        {
            if (FacebookWebContext.Current.IsAuthenticated() && FacebookWebContext.Current.IsAuthorized())
            {
                FacebookClient fbClient   = new FacebookClient(FacebookWebContext.Current.AccessToken);
                dynamic        me         = fbClient.Get("me");
                string         facebookId = (string)me.id;
                string         userEmail  = (string)me.email;

                if (facebookId == null || userEmail == null)
                {
                    throw new FacebookOAuthException();
                }

                var user = market.Users.SingleOrDefault(u => u.Email == userEmail);

                if (user == null)
                {
                    //User does not exist in our DB, let us make him
                    var location = me.location;
                    if (location == null)
                    {
                        location = me.hometown;
                        if (location == null)
                        {
                            var model = new RegisterModel();
                            ModelState.AddModelError("", "Oops, your Facebook profile does not have your location information. Please use the form below to request access.");
                            fbClient.Delete(facebookId + "/permissions");
                            FormsAuthentication.SignOut();
                            return(View(model));
                        }
                    }

                    string[] address = ((string)location.name).Split(',');
                    string   city    = address[0].Trim();
                    string   prov    = address[1].Trim();

                    //Let us create a new user
                    market.Users.Add(new UserModel
                    {
                        Email          = userEmail,
                        FirstName      = (string)me.first_name,
                        LastName       = (string)me.last_name,
                        City           = city,
                        RegionId       = market.Regions.SingleOrDefault(r => r.Name.Contains(prov)).Id,
                        CountryId      = 1,
                        isFacebookUser = true,
                        FacebookUserId = facebookId,
                        ActivationId   = Guid.NewGuid().ToString()
                    });

                    //Let us add a facebook user to our DB with isApproved set to false
                    market.FacebookUsers.Add(new FacebookUser
                    {
                        Id             = facebookId,
                        UserModelEmail = (string)me.email,
                        AccessToken    = FacebookWebContext.Current.AccessToken,
                        IsApproved     = false,
                        Expires        = FacebookWebContext.Current.Session.Expires
                    });

                    market.SaveChanges();
                    Session["REGISTERED_USER"] = true;
                    log.Info("Account - New user registered (" + userEmail.ToLower() + ")");
                    return(View());
                }
                else
                {
                    if (user.isFacebookUser == false)
                    {
                        market.FacebookUsers.Add(new FacebookUser
                        {
                            Id             = facebookId,
                            UserModelEmail = (string)me.email,
                            AccessToken    = FacebookWebContext.Current.AccessToken,
                            IsApproved     = Membership.GetUser(user.Email).IsApproved,
                            Expires        = FacebookWebContext.Current.Session.Expires
                        });

                        market.SaveChanges();

                        user.isFacebookUser      = true;
                        market.Entry(user).State = EntityState.Modified;
                        market.SaveChanges();

                        if (Membership.GetUser(user.Email).IsApproved == true)
                        {
                            FormsAuthentication.SetAuthCookie((string)me.email, false);
                            Session["USER_F_NAME"] = (string)me.first_name;
                            log.Info("Account - User logged in (" + (string)me.email + ")");
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            UserMailer.Welcome(newUser: user).Send();
                            Session["REGISTERED_USER"] = true;
                            log.Info("Account - New user registered (" + user.Email.ToLower() + ")");
                            return(View());
                        }
                    }
                }
            }

            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            ViewBag.RegionId       = new SelectList(market.Regions, "Id", "Name");
            return(View());
        }
예제 #19
0
        public ActionResult RegisterFBPrivateBeta()
        {
            if (FacebookWebContext.Current.IsAuthenticated() && FacebookWebContext.Current.IsAuthorized())
            {
                FacebookClient fbClient   = new FacebookClient(FacebookWebContext.Current.AccessToken);
                dynamic        me         = fbClient.Get("me");
                string         facebookId = (string)me.id;
                string         userEmail  = (string)me.email;

                if (facebookId == null || userEmail == null)
                {
                    throw new FacebookOAuthException();
                }

                var user = market.Users.SingleOrDefault(u => u.Email == userEmail);

                if (user == null)
                {
                    var location = me.location;
                    if (location == null)
                    {
                        location = me.hometown;
                        if (location == null)
                        {
                            var model = new RegisterPrBetaViewModel();
                            ModelState.AddModelError("", "Oops, your Facebook profile does not have your location information. Please use the form below to request access.");
                            fbClient.Delete(facebookId + "/permissions");
                            FormsAuthentication.SignOut();
                            return(View("../Home/Index", model));
                        }
                    }

                    string[] address = ((string)location.name).Split(',');
                    string   city    = address[0].Trim();
                    string   prov    = address[1].Trim();

                    //Let us create a new user
                    market.Users.Add(new UserModel
                    {
                        Email          = userEmail,
                        FirstName      = "Rambla",
                        LastName       = "User",
                        City           = city,
                        RegionId       = market.Regions.SingleOrDefault(r => r.Name.Contains(prov)).Id,
                        CountryId      = 1,
                        isFacebookUser = true,
                        FacebookUserId = facebookId,
                        ActivationId   = Guid.NewGuid().ToString()
                    });

                    //Let us add a facebook user to our DB with isApproved set to false
                    market.FacebookUsers.Add(new FacebookUser
                    {
                        Id             = facebookId,
                        UserModelEmail = (string)me.email,
                        AccessToken    = FacebookWebContext.Current.AccessToken,
                        IsApproved     = false,
                        Expires        = FacebookWebContext.Current.Session.Expires
                    });

                    market.SaveChanges();
                    Session["REQUESTED_ACCESS_USER"] = true;
                    log.Info("Account - New user registered (" + userEmail.ToLower() + ")");
                    return(View("Register"));
                }

                Session["REQUESTED_ACCESS_USER"] = true;
                return(View("Register"));
            }

            var regModel = new RegisterPrBetaViewModel();

            ModelState.AddModelError("", "Oops, your Facebook profile does not have your location information. Please use the form below to request access.");
            return(View("../Home/Index", regModel));
        }