示例#1
0
        public bool PostMessage(string username, PostDetails details)
        {
            try
            {
                var args = new Dictionary<string, object>();
                args["name"] = details.Name ?? string.Empty;
                args["name"] = details.Name ?? string.Empty;
                args["link"] = details.Link ?? string.Empty;
                args["caption"] = details.Caption ?? string.Empty;
                args["description"] = details.Description ?? string.Empty;
                args["picture"] = details.PictureUrl ?? string.Empty;
                args["message"] = details.Message ?? string.Empty;
                args["actions"] = "";

                Post("/" + username + "/feed", args);
                return true;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            return false;
        }
示例#2
0
        private static bool PostFacebookMessage(string[] parameters, string username)
        {
            try
            {
                var details = new PostDetails();
                var options = new Dictionary<string, string>();

                for (int i = 3; i < parameters.Length; i++)
                {
                    string[] keyvalue = parameters[i].Split(':');

                    if (keyvalue.Length > 2)
                        keyvalue[1] += ":" + keyvalue[2];
                    if (keyvalue.Length < 2)
                        return false;
                    keyvalue[1] = keyvalue[1].Trim('\"');
                    options[keyvalue[0]] = keyvalue[1];
                }

                foreach (var keyValuePair in options)
                {
                    switch (keyValuePair.Key)
                    {
                        case "-m":
                            details.Message = keyValuePair.Value;
                            break;
                        case "-n":
                            details.Name = keyValuePair.Value;
                            break;
                        case "-c":
                            details.Caption = keyValuePair.Value;
                            break;
                        case "-l":
                            details.Link = keyValuePair.Value;
                            break;
                        case "-p":
                            details.PictureUrl = keyValuePair.Value;
                            break;
                        case "-d":
                            details.Description = keyValuePair.Value;
                            break;
                        case "-u":
                            break;
                        default:
                            throw new InvalidCommand("Invalid option: " + keyValuePair.Key);
                    }
                }
                _apiManager.FacebookClient.PostMessage(username, details);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }