public static void handleOAuthResult(HttpRequest request, int id) { FacebookOAuthResult oAuthResult; if (FacebookOAuthResult.TryParse(request.Url, out oAuthResult)) { if (oAuthResult.IsSuccess) { string code = request.Params["code"]; FacebookOAuthClient oAuthClient = new FacebookOAuthClient(FacebookApplication.Current); oAuthClient.RedirectUri = new Uri(redirectUrl + "/" + id + "/"); oAuthClient.AppId = ConfigurationManager.AppSettings["Facebook_API_Key"]; oAuthClient.AppSecret = ConfigurationManager.AppSettings["Facebook_API_Secret"]; dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code); string accessToken = tokenResult.access_token; FacebookClient facebookClient = new FacebookClient(accessToken); dynamic me = facebookClient.Get("me"); long facebookId = Convert.ToInt64(me.id); var facebookService = new FacebookService(); FacebookUser fbUser = facebookService.AddFacebookUser(facebookId, accessToken, me.name, me.gender); HttpContext.Current.Session["FBUser"] = fbUser; var _publishedArticleService = new PublishedArticleService(); var article = _publishedArticleService.GetPublishedArticle(id); System.Web.HttpContext.Current.Response.Redirect("/Blog/Details/" + article.headline.Replace(" ", "_") + "/" + article.articleId + "/"); } } }
public void AddFacebookCommentTest() { FacebookService target = new FacebookService(); FBUser fbUser = new FBUser(12345, "a token", "theUsername", "f"); string comment = "this is a facebook comment"; PublishedArticles article = new PublishedArticles(); article.articleId = 1; target.AddFacebookComment(fbUser, comment, article); }
public PartialViewResult FacebookComments(int id) { FacebookUser user = (FacebookUser)Session["FBUser"]; if (user != null) { var comments = new FacebookService().GetCommentsForArticle(id); return PartialView("_FacebookComments", comments); } return null; }