コード例 #1
0
ファイル: FacebookGraphService.cs プロジェクト: dblock/sncore
        public Facebook.Schema.user GetUser(string[] cookieNames, string[] cookieValues)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                Facebook.Session.ConnectSession facebookSession = new Facebook.Session.ConnectSession(
                    ManagedConfiguration.GetValue(session, "Facebook.APIKey", ""),
                    ManagedConfiguration.GetValue(session, "Facebook.Secret", ""));

                TransitAccount ta = new TransitAccount();
                NameValueCollectionSerializer facebookCookies = new NameValueCollectionSerializer(cookieNames, cookieValues);
                facebookSession.SessionKey = facebookCookies.Collection["session_key"];
                facebookSession.UserId = long.Parse(facebookCookies.Collection["user"]);
                
                Facebook.Rest.Api facebookAPI = new Facebook.Rest.Api(facebookSession);
                return facebookAPI.Users.GetInfo();
            }
        }
コード例 #2
0
        public Facebook.Schema.user GetUser(string[] cookieNames, string[] cookieValues)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                Facebook.Session.ConnectSession facebookSession = new Facebook.Session.ConnectSession(
                    ManagedConfiguration.GetValue(session, "Facebook.APIKey", ""),
                    ManagedConfiguration.GetValue(session, "Facebook.Secret", ""));

                TransitAccount ta = new TransitAccount();
                NameValueCollectionSerializer facebookCookies = new NameValueCollectionSerializer(cookieNames, cookieValues);
                facebookSession.SessionKey = facebookCookies.Collection["session_key"];
                facebookSession.UserId     = long.Parse(facebookCookies.Collection["user"]);

                Facebook.Rest.Api facebookAPI = new Facebook.Rest.Api(facebookSession);
                return(facebookAPI.Users.GetInfo());
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // NOTE: The following code must be encapsulated in a try/catch block, otherwise old FB session
            //       keys will cause an exception. Let the FBML/JS on the front-end look for an expired cookie
            //       and re-authenticate accordingly.
            try
            {
                connectSession = new Facebook.Session.ConnectSession(FBAPIKey, FBSecretKey);
                if (!connectSession.IsConnected())
                {
                    // "Please sign-in with Facebook."
                    // Perform all UI functionality here -- user is not yet authenticated.
                }
                else
                {
                    // Once connected, get current user info from the FB API.
                    api = new Facebook.Rest.Api(connectSession);
                    Facebook.Schema.user usr = api.Users.GetInfo();

                    //The page does some reloads and refreshes, dumping out any local scope variables.
                    //We throw them in the sessions so that they can be stored for later.
                    Session["email"] = usr.proxied_email;
                    Session["first"] = usr.first_name;
                    Session["last"] = usr.last_name;
                    Session["full"] = usr.name;

                    // Set custom site variables -- "friendly login name" & identifier
                    OpenID.State.FriendlyLoginName = usr.uid.ToString();
                    OpenID.State.Identifier = usr.uid.ToString();

                    // Create FormsAuthentication ticket...
                    FormsAuthentication.RedirectFromLoginPage(usr.uid.ToString(), false);
                }
            }
            catch (Exception ex)
            {
                // Do nothing...We're expecting an exception.
            }
        }
コード例 #4
0
        private void InitFacebook()
        {
            parameterList = new Dictionary <string, string>();

            try
            {
                if (Instance.Configuration.Options["APIKey"] == null)
                {
                    _apiKey = Instance.ParentInstance.Configuration.Options["APIKey"].ToString();
                }
                else
                {
                    _apiKey = Instance.Configuration.Options["APIKey"].ToString();
                }


                if (Instance.Configuration.Options["sessionKey"] == null)
                {
                    _session = Instance.ParentInstance.Configuration.Options["sessionKey"].ToString();
                }
                else
                {
                    _session = Instance.Configuration.Options["sessionKey"].ToString();
                }

                if (Instance.Configuration.Options["applicationSecret"] == null)
                {
                    _ap_secret = Instance.ParentInstance.Configuration.Options["applicationSecret"].ToString();
                }
                else
                {
                    _ap_secret = Instance.Configuration.Options["applicationSecret"].ToString();
                }

                if (Instance.Configuration.Options["FBaccountID"] == null)
                {
                    _FBaccountID = Instance.ParentInstance.Configuration.Options["FBaccountID"].ToString();
                }
                else
                {
                    _FBaccountID = Instance.Configuration.Options["FBaccountID"].ToString();
                }

                if (Instance.Configuration.Options["applicationID"] == null)
                {
                    _ApplicationID = Instance.ParentInstance.Configuration.Options["applicationID"].ToString();
                }
                else
                {
                    _ApplicationID = Instance.Configuration.Options["applicationID"].ToString();
                }



                if (Instance.Configuration.Options["accountName"] == null)
                {
                    _accoutnName = Instance.ParentInstance.Configuration.Options["accountName"].ToString();
                }
                else
                {
                    _accoutnName = Instance.Configuration.Options["accountName"].ToString();
                }

                if (Instance.Configuration.Options["sessionSecret"] == null)
                {
                    _sessionSecret = Instance.ParentInstance.Configuration.Options["sessionSecret"].ToString();
                }
                else
                {
                    _sessionSecret = Instance.Configuration.Options["sessionSecret"].ToString();
                }


                if (Instance.Configuration.Options["serviceType"] == null)
                {
                    serviceType = Instance.ParentInstance.Configuration.Options["serviceType"].ToString();
                }
                else
                {
                    serviceType = Instance.Configuration.Options["serviceType"].ToString();
                }

                connSession               = new myFacebook.Session.ConnectSession(_apiKey, _ap_secret);
                connSession.SessionKey    = _session;
                connSession.SessionSecret = _sessionSecret;


                _facebookAPI = new myFacebook.Rest.Api(connSession);

                _facebookAPI.Auth.Session.SessionExpires = false;
            }
            catch (Exception ex)
            {
                Edge.Core.Utilities.Log.Write("Error in FacebookBaseRetriever.InitConfigurtaionData(): " + ex.Message, Edge.Core.Utilities.LogMessageType.Error);
            }
        }
コード例 #5
0
ファイル: WebAccountService.cs プロジェクト: dblock/sncore
        public int CreateAccountWithFacebook(string betapassword, string signature, string[] names, string[] values)
        {
            TransitFacebookLogin t_facebook = TryLoginFacebook(signature, names, values);
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;

                string s = ManagedConfiguration.GetValue(session, "SnCore.Beta.Password", string.Empty);
                if (s != betapassword)
                {
                    throw new ManagedAccount.AccessDeniedException();
                }

                ManagedAccount acct = new ManagedAccount(session);

                // fetch account information
                Facebook.Session.ConnectSession facebookSession = new Facebook.Session.ConnectSession(
                    ManagedConfiguration.GetValue(session, "Facebook.APIKey", ""),
                    ManagedConfiguration.GetValue(session, "Facebook.Secret", ""));

                TransitAccount ta = new TransitAccount();
                NameValueCollectionSerializer facebookCookies = new NameValueCollectionSerializer(names, values);
                facebookSession.SessionKey = facebookCookies.Collection["session_key"];
                facebookSession.UserId = t_facebook.FacebookAccountId;
                Facebook.Rest.Api facebookAPI = new Facebook.Rest.Api(facebookSession);
                Facebook.Schema.user user = facebookAPI.Users.GetInfo();
                ta.Name = user.name;
                DateTime birthday = DateTime.Today;
                DateTime.TryParse(user.birthday_date, out birthday);
                ta.Birthday = birthday;
                acct.CreateWithFacebook(t_facebook.FacebookAccountId, user.proxied_email, 
                    ta, ManagedAccount.GetAdminSecurityContext(session));

                if (user.current_location != null)
                {
                    ta.City = user.current_location.city;

                    int country_id;
                    if (ManagedCountry.TryGetCountryId(session, user.current_location.country, out country_id))
                        ta.Country = user.current_location.country;
                    
                    int state_id;
                    if (ManagedState.TryGetStateId(session, user.current_location.state, user.current_location.country, out state_id))
                        ta.State = user.current_location.state;
                }

                if (user.picture_big != null)
                {
                    TransitAccountPicture t_picture = new TransitAccountPicture();
                    t_picture.AccountId = acct.Id;
                    ThumbnailBitmap bitmap = new ThumbnailBitmap(new Bitmap(user.picture_big));
                    t_picture.Bitmap = bitmap.Bitmap;
                    t_picture.Thumbnail = bitmap.Thumbnail;
                    t_picture.Name = user.pic;
                    ManagedAccountPicture m_picture = new ManagedAccountPicture(session);
                    m_picture.CreateOrUpdate(t_picture, ManagedAccount.GetAdminSecurityContext(session));
                }

                SnCore.Data.Hibernate.Session.Flush();
                return acct.Id;
            }
        }
コード例 #6
0
        protected override void GetReportData()
        {
            myFacebook.Rest.Api _facebookAPI = new myFacebook.Rest.Api(connSession);

            //Dictionary<string, string> parameterList = new Dictionary<string, string>();



            //  getAdGroupTargeting Data
            // parameterList.Clear();


            //parameterList.Add("method", "facebook.Auth.createToken");
            //string xx = _facebookAPI.Application.SendRequest(parameterList);
            //xx = xx.Replace("xsd:", "");
            //System.Xml.XmlDocument xmlTargetxx= new System.Xml.XmlDocument();
            //xmlTargetxx.LoadXml(xx);



            //_facebookAPI.Auth.Session.SessionExpires = false;
            ////  getAdGroupTargeting Data
            //parameterList.Clear();
            //parameterList.Add("include_deleted", "true");
            //parameterList.Add("adgroup_ids", "");
            //parameterList.Add("campaign_ids", "");
            //parameterList.Add("account_id", _FBaccountID);
            //parameterList.Add("method", "facebook.Ads.getAdGroupTargeting");
            string url = string.Format("method/ads.getAdGroupTargeting?account_id={0}&include_deleted={1}", _FBaccountID, true);

            string res4 = SendFacebookRequest(url, "getAdGroupTargeting");

            res4 = res4.Replace("xsd:", "");
            System.Xml.XmlDocument xmlTargeting = new System.Xml.XmlDocument();
            xmlTargeting.LoadXml(res4);

            int xmlTargetingount = xmlTargeting.ChildNodes[1].ChildNodes.Count;
            List <Dictionary <string, System.Xml.XmlNode> > ListOfTargets = new List <Dictionary <string, System.Xml.XmlNode> >();


            for (int i = 0; i < xmlTargetingount; i++)
            {
                //  Dictionary<string, System.Xml.XmlNode> newItemTarget = new Dictionary<string, System.Xml.XmlNode>();
                //  newItemTarget.Add(xmlTargeting.ChildNodes[1].ChildNodes[i].ChildNodes[0].InnerText, xmlTargeting.ChildNodes[1].ChildNodes[i]);

                string ageMax, ageMin, sex, birthday, adgroup;
                adgroup  = "0";
                ageMax   = "0";
                ageMin   = "0";
                birthday = "0";
                sex      = "0";
                string education = "0";
                string countries = string.Empty;
                string languages = string.Empty;
                string keywords  = string.Empty;
                string workplace = string.Empty;
                string relation  = "0";

                foreach (var childNode in xmlTargeting.ChildNodes[1].ChildNodes[i].ChildNodes)
                {
                    string NodeName = ((System.Xml.XmlNode)childNode).Name;
                    switch (NodeName)
                    {
                    case "keywords":
                        foreach (var node in ((System.Xml.XmlNode)childNode).ChildNodes)
                        {
                            keywords = keywords + "," + ((System.Xml.XmlNode)node).ChildNodes[0].Value;
                        }
                        break;

                    case "countries":
                        foreach (var node in ((System.Xml.XmlNode)childNode).ChildNodes)
                        {
                            countries = countries + "|" + ((System.Xml.XmlNode)node).ChildNodes[0].Value;
                        }
                        break;

                    case "age_max":
                        ageMax = ((System.Xml.XmlNode)childNode).ChildNodes[0].Value;
                        break;

                    case "age_min":
                        ageMin = ((System.Xml.XmlNode)childNode).ChildNodes[0].Value;
                        break;

                    case "genders":
                        if ((((System.Xml.XmlNode)childNode).ChildNodes.Count == 2))
                        {
                            sex = "3";
                            break;
                        }
                        else
                        {
                            foreach (var node in ((System.Xml.XmlNode)childNode).ChildNodes)
                            {
                                sex = ((System.Xml.XmlNode)node).ChildNodes[0].Value;
                            }
                        }

                        break;

                    case "education_statuses":
                        foreach (var node in ((System.Xml.XmlNode)childNode).ChildNodes)
                        {
                            education = ((System.Xml.XmlNode)childNode).ChildNodes[0].Value;
                        }
                        break;

                    case "adgroup_id":
                        adgroup = ((System.Xml.XmlNode)childNode).ChildNodes[0].Value;
                        break;
                    }
                }


                //ListOfTargets.Add(newItemTarget);
                if (countries.Length > 0)
                {
                    countries = countries.Remove(0, 1);
                }

                if (keywords.Length > 0)
                {
                    keywords = keywords.Remove(0, 1);
                }
                UpdateDB(adgroup, ageMin, ageMax, birthday, languages, workplace, sex, relation, education, countries, keywords);
            }
        }