/// <summary> /// This method lets a user add a like to any post the user can see. A user can like each post only once. /// </summary> /// <example> /// <code> /// private static void RunDemoAsync() /// { /// Api api = new Api(new FBMLCanvasSession(Constants.WebApplicationKey, Constants.WebSecret)); /// api.Stream.AddLikeAsync(Constants.PostId1, AsyncDemoCompleted, null); /// } /// /// private static void AsyncDemoCompleted(bool result, Object state, FacebookException e) /// { /// var actual = result; /// } /// </code> /// </example> /// <param name="postId">The ID of the post.</param> /// <param name="callback">The AsyncCallback delegate</param> /// <param name="state">An object containing state information for this asynchronous request</param> /// <returns>This method returns true on success, or false and an error code if it fails.</returns> public void AddLikeAsync(string postId, AddLikeCallback callback, Object state) { AddLikeAsync(Session.UserId, postId, callback, state); }
/// <summary> /// This method lets a user add a like to any post the user can see. A user can like each post only once. /// </summary> /// <example> /// <code> /// private static void RunDemoAsync() /// { /// Api api = new Api(new FBMLCanvasSession(Constants.WebApplicationKey, Constants.WebSecret)); /// api.Stream.AddLikeAsync(Constants.UserId, Constants.PostId1, AsyncDemoCompleted, null); /// } /// /// private static void AsyncDemoCompleted(bool result, Object state, FacebookException e) /// { /// var actual = result; /// } /// </code> /// </example> /// <param name="uid">The user ID of the user who likes the post. If this parameter is not specified, then it defaults to the session user. Note: This parameter applies only to Web applications. Facebook ignores this parameter if it is passed by a desktop application.</param> /// <param name="postId">The ID of the post.</param> /// <param name="callback">The AsyncCallback delegate</param> /// <param name="state">An object containing state information for this asynchronous request</param> /// <returns>This method returns true on success, or false and an error code if it fails.</returns> public void AddLikeAsync(long uid, string postId, AddLikeCallback callback, Object state) { AddLike(uid, postId, true, callback, state); }
private bool AddLike(long uid, string post_id, bool isAsync, AddLikeCallback callback, Object state) { var parameterList = new Dictionary<string, string> { { "method", "facebook.stream.addLike" } }; Utilities.AddOptionalParameter(parameterList, "uid", uid); Utilities.AddOptionalParameter(parameterList, "post_id", post_id); if (isAsync) { SendRequestAsync<stream_addLike_response, bool>(parameterList, uid <= 0, new FacebookCallCompleted<bool>(callback), state); return true; } var response = SendRequest<stream_addLike_response>(parameterList, uid <= 0); return response == null ? true : response.TypedValue; }