Esempio n. 1
0
        public bool Run(string access_token)
        {
            bool isSuccess = false;

            try
            {
                string url         = string.Format("https://graph.facebook.com/me?access_token={0}&fields=email,name,first_name,last_name,link", access_token);
                var    userInfoStr = CommonFacebookServices.ProcessWebClientRequest(url);

                if (!string.IsNullOrEmpty(userInfoStr))
                {
                    isSuccess = true;
                    var userInfo = JsonConvert.DeserializeObject <FacebookUserInfoModel>(userInfoStr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(isSuccess);
        }
        public async Task <bool> Run(string message)
        {
            bool isSuccess = false;

            try
            {
                var accessToken = CommonFacebookServices.GetAccessToken();

                FacebookClient facebookClient = new FacebookClient(accessToken);
                dynamic        messagePost    = new ExpandoObject();
                messagePost.access_token = accessToken;
                //messagePost.picture = "[A_PICTURE]";
                //messagePost.link = "[SOME_LINK]";
                //messagePost.name = "[SOME_NAME]";
                //messagePost.caption = "my caption";
                messagePost.message = message;
                //messagePost.description = "my description";
                var userId = CommonFacebookServices.GetProfileId(accessToken);

                var result = facebookClient.Post(userId + "/feed", messagePost);

                if (!string.IsNullOrEmpty(result))
                {
                    isSuccess = true;
                }

                Console.WriteLine(result);
            }
            catch (FacebookOAuthException ex)
            {
                //handle something
            }
            catch (Exception ex)
            {
                //handle something else
            }

            return(isSuccess);
        }