Ejemplo n.º 1
0
        private static bool SendMessage(IEnumerable <long> pushIds, string subject, string templatePath, Dictionary <string, string> tokens)
        {
            FacebookOAuthClient oAuth         = new FacebookOAuthClient(FacebookApplication.Current);
            dynamic             tokenResponse = oAuth.GetApplicationAccessToken();
            string accessToken = tokenResponse.access_token;

            FacebookWebClient postApp = new FacebookWebClient(accessToken);

            string body = System.IO.File.ReadAllText(templatePath);

            tokens.Add("CanvasUrl", FacebookApplication.Current.ReturnUrlPath);

            foreach (string key in tokens.Keys)
            {
                body = body.Replace("{" + key + "}", tokens[key]);
            }

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("method", "notifications.sendEmail");
            parameters.Add("recipients", string.Join(",", pushIds));
            parameters.Add("subject", subject);
            parameters.Add("fbml", body);
            dynamic messageResult = postApp.Post(parameters);

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get Application Access Token
        /// </summary>
        /// <returns></returns>
        public string GetAppAccessToken()
        {
            var fb = new FacebookOAuthClient {
                AppId = "340791049284352", AppSecret = "c46526d851aaf7dd547a63ae332d3e49"
            };
            dynamic result         = fb.GetApplicationAccessToken();
            var     appAccessToken = result.access_token;

            return(appAccessToken.ToString());
        }
Ejemplo n.º 3
0
        public void Start()
        {
            Log.Info("Starting");
            this.UpdateTimer = new System.Threading.Timer(delegate(object state)
            {
                try
                {
                    FacebookOAuthClient authClient = new FacebookOAuthClient(FacebookApplication.Current);
                    string token = authClient.GetApplicationAccessToken() as string;

                    FacebookClient facebook  = new FacebookClient(token);
                    IFacebookApplication app = ConfigurationManager.GetSection("facebookSettings") as IFacebookApplication;

                    Dictionary <string, object> authParameters = new Dictionary <string, object>();
                    authParameters.Add("client_id", app.AppId);
                    authParameters.Add("client_secret", app.AppSecret);
                    authParameters.Add("grant_type", "client_credentials");

                    facebook.Get("/oauth/access_token", authParameters);


                    ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings["ComicModelContext"];
                    using (ComicModelContext context = new ComicModelContext(connectionString.ConnectionString))
                    {
                        foreach (User user in context.ListUnsubscriberUsers())
                        {
                            Dictionary <string, object> parameters = new Dictionary <string, object>();
                            parameters.Add("object", "user");
                            parameters.Add("fields", "name,link,email,locale");
                            parameters.Add("callback_url", ComicUrlHelper.GetWebUrl("/User/Subscription"));
                            parameters.Add("verify_token", "erock");


                            //this.Facebook.Post(String.Format("/{0}/subscriptions", ComicConfigSectionGroup.Facebook.AppId), parameters);
                            //this.ActiveUser.IsSubscribed = true;
                        }
                    }
                }
                catch (Exception x)
                {
                    Log.Error(x);
                }
            }, null, new TimeSpan(0, 0, 0), new TimeSpan(1, 0, 0));
        }
Ejemplo n.º 4
0
        protected virtual void SubscribeActiveUser()
        {
            try
            {
                FacebookOAuthClient authClient = new FacebookOAuthClient(FacebookApplication.Current);
                dynamic             auth       = authClient.GetApplicationAccessToken();

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("object", "user");
                parameters.Add("fields", "name,link,email,locale");
                parameters.Add("callback_url", ComicUrlHelper.GetWebUrl("/User/Subscription"));
                parameters.Add("verify_token", VERIFY_TOKEN);

                FacebookClient subscriptionClient = new FacebookClient(auth.access_token);
                subscriptionClient.Post(String.Format("/{0}/subscriptions", ComicConfigSectionGroup.Facebook.AppId), parameters);
            }
            catch (Exception x)
            {
                this.Log.Error("Unable to subscribe.", x);
            }
        }