示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            lblStep1.Visible = false;
            FbLoginBrowser dlg = new FbLoginBrowser();

            dlg.ExtendedPermissions.Add("read_stream");
            dlg.ExtendedPermissions.Add("friends_birthday");
            dlg.ExtendedPermissions.Add("friends_status");
            dlg.ExtendedPermissions.Add("friends_education_history");
            dlg.ExtendedPermissions.Add("friends_relationships");

            dlg.AppId = FbApp.ApplicationKey;
            dlg.ShowDialog();

            if (dlg.Success)
            {
                app = new FacebookApp(dlg.AccessToken);
                var     result  = app.Get("me");
                JObject jobject = JObject.Parse(result.ToString());
                tsStatusMessage.Text = string.Format("Connected as {0}", jobject["name"]);
                me.Name   = (string)jobject["name"];
                me.Gender = (string)jobject["gender"];

                btnGetFriends.Enabled = true;
                btnConnect.Enabled    = false;
                lblStep1.Visible      = true;
            }
            else
            {
                tsStatusMessage.Text = string.Format("FAILED to connect: {0}", dlg.ErrorReason);
            }
        }
        public ActionResult Index()
        {
            string xml;
            FacebookApp app = new FacebookApp();
            JsonObject me = (JsonObject)app.Get("me");
            JsonObject friends = (JsonObject)app.Get("me/friends");
            FacebookFriends facebookFriends = JsonConvert.DeserializeObject<FacebookFriends>(friends.ToString());
            XmlSerializer serializer = new XmlSerializer(typeof(GraphML));
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            List<FacebookUser> users = new List<FacebookUser>();
            GraphML graphML = new GraphML();

            // Add Users
            users.Add(JsonConvert.DeserializeObject<FacebookUser>(me.ToString()));

            foreach (FacebookUser user in facebookFriends.Friends)
            {
                JsonObject friend = (JsonObject)app.Get(user.Id.ToString());
                users.Add(JsonConvert.DeserializeObject<FacebookUser>(friend.ToString()));
            }

            // Prepare the keys
            AddKeys(graphML.Keys);

            // Add the Berico namspace
            namespaces.Add("berico", "http://graph.bericotechnologies.com/xmlns");

            foreach (FacebookUser user in users)
            {
                graphML.Graph.Nodes.Add(Mapper.Map<FacebookUser, Node>(user));
            }

            using (MemoryStream stream = new MemoryStream())
            {
                XmlDocument doc = new XmlDocument();

                serializer.Serialize(stream, graphML, namespaces);
                stream.Seek(0, SeekOrigin.Begin);
                doc.Load(stream);

                // Read the XML into a string object
                xml = doc.OuterXml;
            }

            return this.Content(xml, "txt/xml");
        }
示例#3
0
        public ActionResult Index()
        {
            string                  xml;
            FacebookApp             app             = new FacebookApp();
            JsonObject              me              = (JsonObject)app.Get("me");
            JsonObject              friends         = (JsonObject)app.Get("me/friends");
            FacebookFriends         facebookFriends = JsonConvert.DeserializeObject <FacebookFriends>(friends.ToString());
            XmlSerializer           serializer      = new XmlSerializer(typeof(GraphML));
            XmlSerializerNamespaces namespaces      = new XmlSerializerNamespaces();
            List <FacebookUser>     users           = new List <FacebookUser>();
            GraphML                 graphML         = new GraphML();

            // Add Users
            users.Add(JsonConvert.DeserializeObject <FacebookUser>(me.ToString()));

            foreach (FacebookUser user in facebookFriends.Friends)
            {
                JsonObject friend = (JsonObject)app.Get(user.Id.ToString());
                users.Add(JsonConvert.DeserializeObject <FacebookUser>(friend.ToString()));
            }

            // Prepare the keys
            AddKeys(graphML.Keys);

            // Add the Berico namspace
            namespaces.Add("berico", "http://graph.bericotechnologies.com/xmlns");

            foreach (FacebookUser user in users)
            {
                graphML.Graph.Nodes.Add(Mapper.Map <FacebookUser, Node>(user));
            }

            using (MemoryStream stream = new MemoryStream())
            {
                XmlDocument doc = new XmlDocument();

                serializer.Serialize(stream, graphML, namespaces);
                stream.Seek(0, SeekOrigin.Begin);
                doc.Load(stream);

                // Read the XML into a string object
                xml = doc.OuterXml;
            }

            return(this.Content(xml, "txt/xml"));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            CanvasUrlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, new HttpRequestWrapper(Request));

            var client = new FacebookWebClient();
            PicUrlWebClient = ((dynamic)client.Get("/4", new Dictionary<string, object> { { "fields", "picture" } })).picture;
            
            var app = new FacebookApp();
            PicUrlApp = ((dynamic)app.Get("/4", new Dictionary<string, object> { { "fields", "picture" } })).picture;
        }
示例#5
0
        public void Get_Insights_By_Facebook_Ids()
        {
            dynamic parameters = new ExpandoObject();
            parameters.ids = String.Join(",", 136963329653478, 113767478670024);
            parameters.period = (int)TimeSpan.FromDays(1).TotalSeconds;
            parameters.endtime = (int)DateTime.UtcNow.Date.ToUnixTime();

            var app = new FacebookApp(ConfigurationManager.AppSettings["AccessToken"]);
            var result = app.Get<List<KeyValuePair<string, InsightCollectionItem>>>("/insights", (IDictionary<string, object>)parameters);

            Assert.Equal(2, result.Count);
        }
示例#6
0
        private void btnGetFriends_Click(object sender, EventArgs e)
        {
            lblStep2.Visible = false;
            if (getLimit() == 0)
            {
                MessageBox.Show("Please enter a valid number for the Limit field.", "Limit is invalid");
                return;
            }

            lbFriends.DisplayMember = "Name";
            lbFriends.Items.Clear();
            Dictionary <string, object> parms = new Dictionary <string, object>();

            parms.Add("limit", getLimit());
            if (getOffset() > 0)
            {
                parms.Add("offset", getOffset());
            }

            var result = app.Get("me/friends", parms);

            JObject jobject = JObject.Parse(result.ToString());
            JArray  friends = (JArray)jobject["data"];

            foreach (JObject friend in friends)
            {
                System.Diagnostics.Debug.WriteLine(friend.ToString());
                FbFriend fbFriend = new FbFriend()
                {
                    Name   = (string)friend["name"],
                    UserID = (string)friend["id"]
                };
                Friends.Add(fbFriend.UserID, fbFriend);

                lbFriends.Items.Add(fbFriend);
            }

            btnGetDetails.Enabled = true;
            btnGetStatus.Enabled  = true;
            btnAreFriends.Enabled = true;
            lblStep2.Visible      = true;

            tsStatusMessage.Text = string.Format("Collected {0} friends.", Friends.Count);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            lblStep1.Visible = false;
            FbLoginBrowser dlg = new FbLoginBrowser();
            dlg.ExtendedPermissions.Add("read_stream");
            dlg.ExtendedPermissions.Add("friends_birthday");
            dlg.ExtendedPermissions.Add("friends_status");
            dlg.ExtendedPermissions.Add("friends_education_history");
            dlg.ExtendedPermissions.Add("friends_relationships");

            dlg.AppId = FbApp.ApplicationKey;
            dlg.ShowDialog();

            if (dlg.Success)
            {
                app = new FacebookApp(dlg.AccessToken);
                var result = app.Get("me");
                JObject jobject = JObject.Parse(result.ToString());
                tsStatusMessage.Text = string.Format("Connected as {0}", jobject["name"]);
                me.Name = (string)jobject["name"];
                me.Gender = (string)jobject["gender"];

                btnGetFriends.Enabled = true;
                btnConnect.Enabled = false;
                lblStep1.Visible = true;

            }
            else
                tsStatusMessage.Text = string.Format("FAILED to connect: {0}", dlg.ErrorReason);
        }
示例#8
0
        /*
        private fbuser Setfbid()
        {
            string oauth = "";
            oauth = HttpContext.Current.Request.QueryString["code"].ToString();
            //oauth = oauth.Substring(0, oauth.IndexOf("|"));
            fbuser fbuser = new fbuser();
            //oauth = oauth.Substring(0, oauth.IndexOf("|"));

            WebClient wc = new WebClient();
            wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters
            //string result = wc.DownloadString("https://graph.facebook.com/oauth/access_token?response_type=token&client_secret=" + ConfigurationManager.AppSettings.Get("Secret").ToString() + "&client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&code=" + oauth);
            string strsend = "https://graph.facebook.com/oauth/access_token?client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + thereturnpage + "&client_secret=" + ConfigurationManager.AppSettings.Get("Secret").ToString() + "&code=" + oauth;
            var url = "https://graph.facebook.com/oauth/authorize?client_id=" + ConfigurationSettings.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + ConfigurationSettings.AppSettings.Get("App_URL").ToString() + "default.aspx&scope=" + strrequiredAppPermissions;
            string result = wc.DownloadString(url);
            string accesstoken = result.Replace("access_token=", "");
            int endofaccesstoken = accesstoken.IndexOf("&expire");
            accesstoken = accesstoken.Substring(0, endofaccesstoken);

            //Get user id
            wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters
            string result2 = wc.DownloadString("https://graph.facebook.com/me?access_token=" + accesstoken);

            try
            {
                JObject o = JObject.Parse(result2);
                string fbid = (string)o["id"];
                string email = "";
                string firstname = "";
                string lastname = "";
                if (o["email"] != null)
                {
                    email = (string)o["email"];
                }
                if (o["first_name"] != null)
                {
                    firstname = (string)o["first_name"];
                }
                if (o["last_name"] != null)
                {
                    lastname = (string)o["last_name"];
                }

                bool isnewuser = false;

                BlueIkons_DB.SPs.UpdateFBUser(Convert.ToInt64(fbid), firstname, lastname, email, accesstoken).Execute();
                fbuser.UID = Convert.ToInt64(fbid);
                fbuser.Email = email;
                fbuser.Firstname = firstname;
                fbuser.Lastname = lastname;
                fbuser.AccessToken = accesstoken;

            }
            catch
            {
            }

            return fbuser;
        }*/
        protected fbuser PopulatefbuserGraph()
        {
            CanvasAuthorizer authorizer;
            fbuser localfbuser = new fbuser();
            FacebookApp fbApp = new FacebookApp();

            authorizer = new CanvasAuthorizer();
            authorizer.Permissions = requiredAppPermissions;
            //if ((authorizer.Session != null) || ((HttpContext.Current.Request.QueryString["code"] != null) && (HttpContext.Current.Request.QueryString["code"] != "")))
            if (authorizer.Session != null)
            {
                //ShowFacebookContent();
                JsonObject myInfo = (JsonObject)fbApp.Get("me");

                localfbuser.UID = Convert.ToInt64(myInfo["id"].ToString());
                localfbuser.AccessToken = fbApp.AccessToken;
                localfbuser.SessionKey = fbApp.Session.Signature;
                localfbuser.Firstname = myInfo["first_name"].ToString();
                localfbuser.Lastname = myInfo["last_name"].ToString();
                localfbuser.Fullname = localfbuser.Firstname + " " + localfbuser.Lastname;
                localfbuser.Email = getfbappemail(myInfo);

                //HttpContext.Current.Session["fbuser"] = fbuser;
                BlueIkons_DB.SPs.UpdateFBUser(localfbuser.UID, localfbuser.Firstname, localfbuser.Lastname, localfbuser.Email, localfbuser.AccessToken).Execute();

                if ((HttpContext.Current.Session["invite"] != null) || (HttpContext.Current.Request.QueryString["invite"] != null))
                {
                    updateinvite(localfbuser);
                }
                //Eventomatic_DB.SPs.UpdateResource(fbuser.UID, fbuser.Firstname, fbuser.Lastname, "", HttpContext.Current.Request.UserHostAddress, GetCurrentPageName(), 0, 0, fbuser.SessionKey, fbuser.AccessToken, 0).Execute();
            }
            else if ((HttpContext.Current.Request.QueryString["fbid"] != null) && (HttpContext.Current.Request.QueryString["fbid"] != ""))
            {
                localfbuser = Getfbuser(Convert.ToInt64(HttpContext.Current.Request.QueryString["fbid"].ToString()));
                if (HttpContext.Current.Request.QueryString["invite"] != null)
                {
                    updateinvite(localfbuser);
                }
                //HttpContext.Current.Session["fbuser"] = fbuser;
            }
            else
            {
                if (HttpContext.Current.Request.QueryString["invite"] != null)
                {
                    //remember invitekey
                    HttpContext.Current.Session["invite"] = HttpContext.Current.Request.QueryString["invite"].ToString();
                }
                var pageName = Path.GetFileName(HttpContext.Current.Request.PhysicalPath);
                var urlSB = new StringBuilder();
                urlSB.Append("https://graph.facebook.com/oauth/authorize?client_id=");
                urlSB.Append(ConfigurationManager.AppSettings["fbAppID"]);
                urlSB.Append("&redirect_uri=");
                urlSB.Append(ConfigurationManager.AppSettings["App_URL"]);
                urlSB.Append(pageName);
                urlSB.Append("&scope=");
                urlSB.Append(strrequiredAppPermissions);
                //var url = authorizer.ge auth.GetLoginUrl(new HttpRequestWrapper(Request));
                Uri newuri = new Uri(urlSB.ToString());
                var content = CanvasUrlBuilder.GetCanvasRedirectHtml(newuri);
                HttpContext.Current.Response.ContentType = "text/html";
                HttpContext.Current.Response.Write(content);
                HttpContext.Current.Response.End();
            }
            return localfbuser;
        }