Example #1
0
 public bool AddPhoto(PhotoDetails photoDetails)
 {
     var mediaObject = new FacebookMediaObject
     {
         FileName = photoDetails.FacebookName,
         ContentType = "image/jpeg"
     };
     byte[] fileBytes = photoDetails.ImageStream;
     mediaObject.SetValue(fileBytes);
     IDictionary<string, object> upload = new Dictionary<string, object>();
     upload.Add("name", photoDetails.FacebookName);
     upload.Add("message", photoDetails.PhotoDescription);
     upload.Add("@file.jpg", mediaObject);
     Post("/" + photoDetails.AlbumId + "/photos", upload);
     return true;
 }
Example #2
0
        private static bool PostFacebookPhoto(string[] parameters, string username)
        {
            try
            {
                var photoDetails = new PhotoDetails();

                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.Add(keyValue[0], keyValue[1]);
                }

                foreach (var keyValuePair in options)
                {
                    switch (keyValuePair.Key)
                    {
                        case "-u":
                            username = keyValuePair.Value;
                            break;
                        case "-pn":
                            photoDetails.FacebookName = keyValuePair.Value;
                            break;
                        case "-pd":
                            photoDetails.PhotoDescription = keyValuePair.Value;
                            break;
                        case "-aid":
                            photoDetails.AlbumId = keyValuePair.Value;
                            break;
                        case "-ad":
                            photoDetails.AlbumDescription = keyValuePair.Value;
                            break;
                        case "-an":
                            photoDetails.AlbumName = keyValuePair.Value;
                            break;
                        case "-p":
                            photoDetails.ImageStream = File.ReadAllBytes(keyValuePair.Value);
                            break;
                    }
                }
                if (string.IsNullOrEmpty(photoDetails.AlbumId) && username.CompareTo("me") == 0)
                {
                    photoDetails.AlbumId = ChooseAlbumId(username);
                }
                else photoDetails.AlbumId = username;
                return _apiManager.FacebookClient.AddPhoto(photoDetails);
            }
            catch
            {
                return false;
            }
        }