コード例 #1
0
        internal static UniversalProfile ProfileFromFacebook(FacebookGraph graph)
        {
            var profile = new UniversalProfile
            {
                BirthDay    = graph.Birthday,
                Link        = graph.Link.ToString(),
                FirstName   = graph.FirstName,
                LastName    = graph.LastName,
                Gender      = graph.Gender,
                DisplayName = graph.FirstName + graph.LastName,
                EMail       = graph.Email,
                Id          = graph.Id.ToString(),
                TimeZone    = graph.Timezone,
                Locale      = graph.Locale,
                Provider    = "facebook"
            };

            return(profile);
        }
コード例 #2
0
ファイル: Facebook.aspx.cs プロジェクト: terry2012/DSV
        protected void Page_Load(object sender, EventArgs e)
        {
            IAuthorizationState authorization = client.ProcessUserAuthorization();

            if (authorization == null)
            {
                // Kick off authorization request
                client.RequestUserAuthorization();
            }
            else
            {
                var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
                using (var response = request.GetResponse()) {
                    using (var responseStream = response.GetResponseStream()) {
                        var graph = FacebookGraph.Deserialize(responseStream);
                        this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
                    }
                }
            }
        }
コード例 #3
0
        internal static LoginProfile ProfileFromFacebook(FacebookGraph graph)
        {
            var profile = new LoginProfile
                              {
                                  BirthDay = graph.Birthday,
                                  Link = graph.Link.ToString(),
                                  FirstName = graph.FirstName,
                                  LastName = graph.LastName,
                                  Gender = graph.Gender,
                                  DisplayName = graph.FirstName + graph.LastName,
                                  EMail = graph.Email,
                                  Id = graph.Id.ToString(),
                                  TimeZone = graph.Timezone,
                                  Locale = graph.Locale,
                                  Provider = ProviderConstants.Facebook,
                                  Avatar = string.Format("http://graph.facebook.com/{0}/picture", graph.Id)
                              };

            return profile;
        }
コード例 #4
0
        private void addFacebookPage(SocialPageFormViewModel model)
        {
            var url = Regex.Match(model.Url, @"http(s)?:\/\/(www\.)?facebook\.com\/[^\/\s]+").ToString();

            if (String.IsNullOrWhiteSpace(url))
            {
                throw new BadLinkException("Please enter a valid facebook page");
            }
            FacebookGraph fbGraph = new FacebookGraph(url);

            FacebookPage fbPage = new FacebookPage()
            {
                Name = model.Name,
                Url  = url,
                Cpc  = model.Cpc
            };


            var facebookId     = fbGraph.takeFacebookId();
            var fbAlreadyAdded = _context.Facebooks.SingleOrDefault(fb => fb.FacebookCode == facebookId);
            var currentUserId  = User.Identity.GetUserId();

            if (fbAlreadyAdded == null)
            {
                fbPage.FacebookCode = facebookId;
                fbPage.UserId       = currentUserId;

                _context.Facebooks.Add(fbPage);
            }
            else
            {
                if (fbAlreadyAdded.UserId == currentUserId)
                {
                    fbAlreadyAdded.Deleted = false;
                }
                else
                {
                    throw new LinkAlreadyExistException("Link is already added on this social network");
                }
            }
        }
コード例 #5
0
ファイル: Facebook.aspx.cs プロジェクト: jn7163/GiftR
        protected void Page_Load(object sender, EventArgs e)
        {
            IAuthorizationState authorization = client.ProcessUserAuthorization();

            if (authorization == null)
            {
                // Kick off authorization request
                client.RequestUserAuthorization();
            }
            else
            {
                var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
                using (var response = request.GetResponse()) {
                    using (var responseStream = response.GetResponseStream()) {
                        var graph = FacebookGraph.Deserialize(responseStream);

                        Response.RedirectWithQueryString(PageFlowExtensions.GetDefaultPageUrl().AbsoluteUri);
                    }
                }
            }
        }
コード例 #6
0
        public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary<string, string> @params)
        {
            var builder = new UriBuilder(context.Request.GetUrlRewriter()) {Query = "p=" + context.Request["p"]};
            var oauth = new FacebookOAuthClient
            {
                AppId = KeyStorage.Get("facebookAppID"),
                AppSecret = KeyStorage.Get("facebookAppSecret"),
                RedirectUri = builder.Uri
            };
            FacebookOAuthResult result;
            if (FacebookOAuthResult.TryParse(context.Request.GetUrlRewriter(), out result))
            {
                if (result.IsSuccess)
                {
                    var accessToken = (Facebook.JsonObject)oauth.ExchangeCodeForAccessToken(result.Code);
                    var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString((string)accessToken["access_token"]));
                    using (var response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            var graph = FacebookGraph.Deserialize(responseStream);
                            var profile = ProfileFromFacebook(graph);
                            return profile;
                        }
                    }
                }
                return LoginProfile.FromError(new Exception(result.ErrorReason));
            }
            //Maybe we didn't query
            var extendedPermissions = new[] { "email", "user_about_me" };
            var parameters = new Dictionary<string, object>
                                 {
                                     { "display", "popup" }
                                 };

            if (extendedPermissions.Length > 0)
            {
                var scope = new StringBuilder();
                scope.Append(string.Join(",", extendedPermissions));
                parameters["scope"] = scope.ToString();
            }
            var loginUrl = oauth.GetLoginUrl(parameters);
            context.Response.Redirect(loginUrl.ToString());
            return LoginProfile.FromError(new Exception("Failed to login with facebook"));




            //var client = new FacebookClient
            //                 {
            //                     ClientIdentifier = KeyStorage.Get("facebookAppID"),
            //                     ClientSecret = KeyStorage.Get("facebookAppSecret"),
            //                 };
            //try
            //{
            //    IAuthorizationState authorization = client.ProcessUserAuthorization(new HttpRequestInfo(context.Request));
            //    if (authorization == null)
            //    {
            //        // Kick off authorization request
            //        var scope = new List<string>()
            //                    {
            //                        "email,user_about_me",
            //                    };
            //        client.RequestUserAuthorization(scope, null, null);
            //    }
            //    else
            //    {
            //        var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
            //        using (var response = request.GetResponse())
            //        {
            //            if (response != null)
            //                using (var responseStream = response.GetResponseStream())
            //                {
            //                    var graph = FacebookGraph.Deserialize(responseStream);
            //                    var profile = ProfileFromFacebook(graph);
            //                    return profile;
            //                }
            //        }
            //    }
            //}
            //catch (ProtocolException e)
            //{
            //    if (e.InnerException is WebException)
            //    {
            //        //Read stream
            //        var responce =
            //            new StreamReader((e.InnerException as WebException).Response.GetResponseStream()).ReadToEnd();
            //    }
            //    throw;
            //}

        }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: havee/GiftR
        public bool FacebookAuthorization(out FacebookGraph fbUser)
        {
            IAuthorizationState authorization = client.ProcessUserAuthorization();
            if (authorization == null)
            {
                client.RequestUserAuthorization();
            }
            else
            {
                try
                {
                    var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
                    using (var response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            fbUser = FacebookGraph.Deserialize(responseStream);

                            return true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    fbUser = null;
                    return false;
                }
            }

            fbUser = null;
            return false;
        }