public ActivityPost PublishStream(FacebookObjectId targetId, string message) { var streamMap = new METHOD_MAP { { "method", "stream.publish" }, { "message", message }, { "target_id", targetId.ToString() }, }; Utility.FailableFunction(() => _SendRequest(streamMap)); // Return a proxy that looks close to what we expect the updated status to look like. // We'll replace it with the real one the next time we sync. return(new ActivityPost(_Service) { ActorUserId = _UserId, TargetUserId = targetId, Attachment = null, CanComment = false, CanLike = false, CanRemoveComments = false, CommentCount = 0, Created = DateTime.Now, HasLiked = false, LikedCount = 0, LikeUri = null, Message = message, PostId = new FacebookObjectId("-1"), RawComments = new FBMergeableCollection <ActivityComment>(), Updated = DateTime.Now, }); }
public void RemoveLike(FacebookObjectId postId) { var likeMap = new METHOD_MAP { { "method", "stream.removeLike" }, { "post_id", postId.ToString() }, }; Utility.FailableFunction(() => _SendRequest(likeMap)); }
public List <FacebookPhotoTag> GetPhotoTags(FacebookObjectId photoId) { var tagMap = new METHOD_MAP { { "method", "photos.getTags" }, { "pids", photoId.ToString() }, }; string response = Utility.FailableFunction(() => _SendRequest(tagMap)); return(_jsonSerializer.DeserializePhotoTagsList(response)); }
public bool GetPhotoCanComment(FacebookObjectId photoId) { var commentMap = new METHOD_MAP { { "method", "photos.canComment" }, { "pid", photoId.ToString() }, }; string response = Utility.FailableFunction(() => _SendRequest(commentMap)); return(_jsonSerializer.DeserializePhotoCanCommentResponse(response)); }
public FacebookObjectId AddPhotoComment(FacebookObjectId photoId, string comment) { var addMap = new METHOD_MAP { { "method", "photos.addComment" }, { "pid", photoId.ToString() }, { "body", comment }, }; string response = Utility.FailableFunction(() => _SendRequest(addMap)); return(_jsonSerializer.DeserializePhotoAddCommentResponse(response)); }
internal UnfriendNotification(FacebookService service, FacebookObjectId userId) : base(service) { Created = default(DateTime); Updated = default(DateTime); IsHidden = false; IsUnread = true; NotificationId = new FacebookObjectId("Unfriended_" + userId.ToString()); RecipientId = service.UserId; SenderId = userId; Sender.PropertyChanged += _OnSenderPropertyChanged; Title = string.Format(_friendRemovalFormat, Sender.ProfileUri.ToString(), Sender.Name); TitleText = string.Format(_friendRemovalTextFormat, Sender.Name); Link = Sender.ProfileUri; }
public void RemoveComment(FacebookObjectId commentId) { if (!FacebookObjectId.IsValid(commentId)) { // If we're removing a comment that we haven't yet posted we can't remove it. return; } var commentMap = new METHOD_MAP { { "method", "stream.removeComment" }, { "comment_id", commentId.ToString() }, }; Utility.FailableFunction(() => _SendRequest(commentMap)); }
public ActivityPost UpdateStatus(string newStatus) { var statusMap = new METHOD_MAP { { "method", "status.set" }, { "status", newStatus }, { "uid", _UserId.ToString() }, }; string result = Utility.FailableFunction(() => _SendRequest(statusMap)); bool success = _jsonSerializer.DeserializeStatusSetResponse(result); Assert.IsTrue(success); // Return a proxy that looks close to what we expect the updated status to look like. // We'll replace it with the real one the next time we sync, unless a feed is being shown // from which this should be excluded. return(new ActivityPost(_Service) { ActorUserId = _UserId, Attachment = null, CanComment = false, CanLike = false, CanRemoveComments = false, CommentCount = 0, Created = DateTime.Now, HasLiked = false, LikedCount = 0, LikeUri = null, Message = newStatus, PostId = new FacebookObjectId("FakeStatusId"), RawComments = new FBMergeableCollection <ActivityComment>(), TargetUserId = default(FacebookObjectId), Updated = DateTime.Now, }); }
public List <FacebookPhotoTag> AddPhotoTag(FacebookObjectId photoId, FacebookObjectId userId, float x, float y) { Verify.IsTrue(FacebookObjectId.IsValid(userId), "Invalid userId"); Verify.IsTrue(FacebookObjectId.IsValid(photoId), "Invalid photoId"); x *= 100; y *= 100; var tagMap = new METHOD_MAP { { "method", "photos.addTag" }, { "pid", photoId.ToString() }, { "tag_uid", userId.ToString() }, { "x", string.Format("{0:0.##}", x) }, { "y", string.Format("{0:0.##}", y) }, }; string response = Utility.FailableFunction(() => _SendRequest(tagMap)); return(GetPhotoTags(photoId)); }
public FacebookPhotoAlbum GetAlbum(FacebookObjectId albumId) { Verify.IsTrue(FacebookObjectId.IsValid(albumId), "Invalid albumId"); var albumMap = new METHOD_MAP { { "method", "photos.getAlbums" }, { "aids", albumId.ToString() }, }; string response = Utility.FailableFunction(() => _SendRequest(albumMap)); List <FacebookPhotoAlbum> albumsResponse = _jsonSerializer.DeserializeGetAlbumsResponse(response); Assert.IsFalse(albumsResponse.Count > 1); if (albumsResponse.Count == 0) { return(null); } return(albumsResponse[0]); }
public FacebookContact TryGetUser(FacebookObjectId userId, bool getFullData) { _Verify(); var userMap = new METHOD_MAP { { "method", "users.GetInfo" }, { "uids", userId.ToString() }, //{ "fields", _UserColumns }, }; if (getFullData) { userMap["fields"] = _UserColumns; } else { userMap["fields"] = _UserColumnsLite; } // Facebook bogusly errors this call fairly frequently. List <FacebookContact> contactList = null; int reaskCount = 0; do { string result = Utility.FailableFunction(5, () => _SendRequest(userMap)); contactList = _jsonSerializer.DeserializeUsersList(result); } while (contactList.Count == 0 && ++reaskCount < 3); if (contactList.Count == 0) { // I'd like to do something better here. This fails too frequently. // Maybe once we move to the graph API there will be a more privacy friendly way to get this data. return(null); //throw new FacebookException("Unable to obtain information about the user.", null); } return(contactList[0]); }
public FacebookPhoto AddPhotoToAlbum(FacebookObjectId albumId, string caption, string imageFile) { _Verify(); var updateMap = new METHOD_MAP { { "method", "photos.upload" }, }; if (FacebookObjectId.IsValid(albumId)) { updateMap.Add("aid", albumId.ToString()); } if (!string.IsNullOrEmpty(caption)) { updateMap.Add("caption", caption); } string response = Utility.FailableFunction(() => _SendFileRequest(updateMap, imageFile)); return(_jsonSerializer.DeserializePhotoUploadResponse(response)); }
private void _GetUserInfo() { _ClearUserInfo(); try { string userPath = Path.Combine(_settingsRootPath, UserId.ToString()); Utility.EnsureDirectory(userPath); string userSettingPath = Path.Combine(userPath, _UserSettingsFileName); if (!File.Exists(userSettingPath)) { return; } XDocument xdoc = XDocument.Load(userSettingPath); // Currently not providing a migration path from v1 settings. // Consider doing this in the future, or a path from 2 if we add a v3. // It's also worth noting that if an older version gets run, the way these are implemented will tend to stomp over each other. if (2 != (int)xdoc.Root.Attribute("v")) { return; } XElement contactsElement = xdoc.Root.Element("friends"); if (contactsElement != null) { double il = 0; foreach (var contact in from contactNode in contactsElement.Elements("contact") let isDouble = double.TryParse((string)contactNode.Attribute("interestLevel"), out il) select new _LiteContact { UserId = new FacebookObjectId((string)contactNode.Attribute("uid")), Name = (string)contactNode.Attribute("name"), InterestLevel = (isDouble ? (double?)il : null) }) { _friendLookup.Add(contact.UserId, contact); } } XElement knownFriendRequestsElement = xdoc.Root.Element("knownFriendRequests"); if (knownFriendRequestsElement != null) { _ignoredFriendRequests.AddRange(from contactNode in knownFriendRequestsElement.Elements("contact") select new FacebookObjectId((string)contactNode.Attribute("uid"))); } XElement unknownFriendRemovalsElement = xdoc.Root.Element("unreadUnfriendings"); if (unknownFriendRemovalsElement != null) { _unknownFriendRemovals.AddRange(from contactNode in knownFriendRequestsElement.Elements("contact") select new FacebookObjectId((string)contactNode.Attribute("uid"))); } XElement readMessagesElement = xdoc.Root.Element("readMessages"); if (readMessagesElement != null) { _readMessages.AddRange(from messageNode in readMessagesElement.Elements("message") select new FacebookObjectId((string)messageNode.Attribute("id"))); } _hasUserInfo = true; } catch { _ClearUserInfo(); throw; } }