/// <summary> /// Creates a new list for the authenticated user. Note that you can't create more than 20 lists per account. /// </summary> /// <param name="name"></param> /// <param name="mode"></param> /// <param name="description"></param> /// <returns></returns> public TwitterList CreateList(string name, TwitterListMode mode = TwitterListMode.Public, string description = null) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "name", name }, { "mode", mode.ToString().ToLowerInvariant() } }; if (!String.IsNullOrEmpty(description)) { postData.Add("description", description); } var uri = new Uri(this.CommandBaseUri + "/create.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var list = TwitterObject.Parse <TwitterList>(response); return(list); }
private TwitterList UnsubscribeFromList(string listId, string slug, string ownerScreenName, string ownerId) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string>(); if (!String.IsNullOrEmpty(listId)) { postData.Add("list_id", listId); } if (!String.IsNullOrEmpty(slug)) { postData.Add("slug", slug); } if (!String.IsNullOrEmpty(ownerId)) { postData.Add("owner_id", ownerId); } if (!String.IsNullOrEmpty(ownerScreenName)) { postData.Add("owner_screen_name", ownerScreenName); } var uri = new Uri(this.CommandBaseUri + "/subscribers/destroy.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var list = TwitterObject.Parse <TwitterList>(response); return(list); }
/// <summary> /// Returns the lists of the specified (or authenticated) user. Private lists will be included /// if the authenticated user is the same as the user whose lists are being returned. /// </summary> /// <param name="screenName"></param> /// <param name="userId"></param> /// <param name="cursor"></param> /// <returns></returns> public TwitterCursorPagedListCollection RetrieveUserCreatedLists(string screenName, string userId = null, string cursor = "-1") { if (String.IsNullOrEmpty(screenName) && String.IsNullOrEmpty(userId)) { throw new ArgumentException("A user id or screen name must be provided."); } var queryBuilder = new StringBuilder(); queryBuilder.AppendFormat("?cursor={0}&", !String.IsNullOrEmpty(cursor) ? cursor : "-1"); if (!String.IsNullOrEmpty(screenName)) { queryBuilder.AppendFormat("screen_name={0}&", screenName); } if (!String.IsNullOrEmpty(userId)) { queryBuilder.AppendFormat("&user_id={0}", userId); } var uri = new Uri(this.CommandBaseUri + String.Format(".json{0}", queryBuilder.ToString().TrimEnd('&'))); var response = this.TwitterApi.Authenticated ? this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null) : this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var lists = TwitterObject.Parse <TwitterCursorPagedListCollection>(response); return(lists); }
/// <summary> /// Use this method to test if supplied user credentials are valid. /// </summary> /// <param name="twitterUser"></param> /// <returns> /// Returns true if credentials are valid. Otherwise, false. /// </returns> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="TwitterException"></exception> public bool VerifyCredentials(out TwitterUser twitterUser) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } twitterUser = null; var valid = false; var uri = new Uri(this.CommandBaseUri + "/verify_credentials.json"); try { var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null); twitterUser = TwitterObject.Parse <TwitterUser>(response); valid = true; } catch (TwitterException e) { if (e.StatusCode != HttpStatusCode.Unauthorized) { throw; } } return(valid); }
/// <summary> /// Returns extended information of a given user, specified by ID or screen name as per the /// required id parameter. The author's most recent status will be returned inline. /// </summary> /// <param name="screenName"></param> /// <param name="userId"></param> /// <param name="includeEntities"></param> /// <returns></returns> public TwitterUser Show(string screenName, string userId = null, bool includeEntities = true) { if (String.IsNullOrEmpty(screenName) && String.IsNullOrEmpty(userId)) { throw new ArgumentException("Either a userId or screenName is required for this method."); } var queryBuilder = new StringBuilder(); queryBuilder.AppendFormat("?include_entities={0}&", includeEntities ? "true" : "false"); if (!String.IsNullOrEmpty(screenName)) { queryBuilder.AppendFormat("screen_name={0}&", screenName); } if (!String.IsNullOrEmpty(userId)) { queryBuilder.AppendFormat("user_id={0}", userId); } var uri = new Uri(this.CommandBaseUri + "/show.json" + queryBuilder.ToString().TrimEnd('&')); var response = this.TwitterApi.Authenticated ? this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null) : this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var user = TwitterObject.Parse <TwitterUser>(response); return(user); }
/// <summary> /// Retweets a tweet. Returns the original tweet with retweet details embedded. /// </summary> /// <param name="id"></param> /// <param name="trimUser"></param> /// <param name="includeEntities"></param> /// <returns></returns> public TwitterTweet Retweet(string id, bool trimUser = false, bool includeEntities = true) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var uriBuilder = new UriBuilder(this.CommandBaseUri); uriBuilder.Path += String.Format("/retweet/{0}.json", id); var postData = new Dictionary <string, string> { { "trim_user", trimUser ? "true" : "false" }, { "include_entities", includeEntities ? "true" : "false" } }; var response = this.TwitterApi.ExecuteAuthenticatedRequest(uriBuilder.Uri, HttpMethod.Post, postData); var tweet = TwitterObject.Parse <TwitterTweet>(response); return(tweet); }
/// <summary> /// Returns all the information about a known place. /// </summary> /// <param name="placeId">A place in the world. These IDs can be retrieved from ReverseGeocode method.</param> /// <returns></returns> public TwitterPlace RetrievePlaceById(string placeId) { if (String.IsNullOrEmpty(placeId)) { throw new ArgumentException(); } var uri = new Uri(this.CommandBaseUri + String.Format("/id/{0}.json", placeId)); TwitterPlace place = null; try { var response = this.TwitterApi.ExecuteUnauthenticatedRequest(uri); place = TwitterObject.Parse <TwitterPlace>(response); } catch (TwitterException e) { if (e.StatusCode != HttpStatusCode.NotFound) { throw; } } return(place); }
/// <summary> /// Creates a new place object at the given latitude and longitude. /// </summary> /// <param name="name">The name a place is known as.</param> /// <param name="containedWithin"></param> /// <param name="token"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="streetAddress"></param> /// <returns></returns> /// <remarks> /// Before creating a place you need to query GET geo/similar_places with the latitude, longitude and /// name of the place you wish to create. The query will return an array of places which are similar /// to the one you wish to create, and a token. If the place you wish to create isn't in the returned /// array you can use the token with this method to create a new one. /// </remarks> public TwitterPlace CreatePlace(string name, string containedWithin, string token, string latitude, string longitude, string streetAddress = null) { if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(containedWithin) || String.IsNullOrEmpty(token) || String.IsNullOrEmpty(latitude) || String.IsNullOrEmpty(longitude)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "name", name }, { "contained_within", containedWithin }, { "token", token }, { "lat", latitude }, { "long", longitude } }; if (!String.IsNullOrEmpty(streetAddress)) { postData.Add("attribute:street_address", streetAddress); } var uri = new Uri(this.CommandBaseUri + "/place.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var place = TwitterObject.Parse <TwitterPlace>(response); return(place); }
/// <summary> /// Returns the lists the specified user has been added to. /// If user id or screen name are not provided the memberships for the authenticating user are returned. /// </summary> /// <param name="screenName"></param> /// <param name="userId"></param> /// <param name="cursor"></param> /// <param name="ownedList"></param> /// <returns></returns> public TwitterCursorPagedListCollection RetrieveMemberships(string screenName = null, string userId = null, string cursor = "-1", bool ownedList = false) { var queryBuilder = new StringBuilder(); queryBuilder.AppendFormat("?cursor={0}&filter_to_owned_lists={1}&", !String.IsNullOrEmpty(cursor) ? cursor : "-1", ownedList ? "true" : "false"); if (!String.IsNullOrEmpty(screenName)) { queryBuilder.AppendFormat("screen_name={0}&", screenName); } if (!String.IsNullOrEmpty(userId)) { queryBuilder.AppendFormat("&user_id={0}", userId); } var uri = new Uri(this.CommandBaseUri + String.Format("/memberships.json{0}", queryBuilder.ToString().TrimEnd('&'))); var response = this.TwitterApi.Authenticated ? this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null) : this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var lists = TwitterObject.Parse <TwitterCursorPagedListCollection>(response); return(lists); }
/// <summary> /// Allows the authenticating users to unfollow the user specified in the ID parameter. /// </summary> /// <param name="screenName"></param> /// <param name="userId"></param> /// <param name="includeEntities"></param> /// <returns>Returns the unfollowed user when successful.</returns> public TwitterUser Destroy(string screenName, string userId = null, bool includeEntities = true) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "include_entities", includeEntities ? "true" : "false" } }; if (screenName != null) { postData.Add("screen_name", screenName); } if (userId != null) { postData.Add("user_id", userId); } if (postData.Count == 1) { throw new ArgumentException("Either the userIds or screenNames is required for this method."); } var uri = new Uri(this.CommandBaseUri + "/destroy.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var user = TwitterObject.Parse <TwitterUser>(response); return(user); }
private void btnTestTwitter_Click(object sender, RoutedEventArgs e) { if ((this.gvTwitter.SelectedItems.Count == 1) && (this.gvTwitter.SelectedItem is TwitterObject)) { TwitterObject selectedItem = this.gvTwitter.SelectedItem as TwitterObject; new Notificator().Tweet(Notificator.NotificationType.Restock, selectedItem); } }
/// <summary> /// Updates the authenticating dm's status, also known as tweeting. /// To upload an image to accompany the tweet, use UpdateWithMedia method. /// </summary> /// <param name="status"></param> /// <param name="inReplyToStatusId"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="placeId"></param> /// <param name="displayCoordinates"></param> /// <param name="trimUser"></param> /// <param name="includeEntities"></param> /// <returns></returns> public TwitterTweet Update(string status, string inReplyToStatusId = null, double latitude = double.NaN, double longitude = double.NaN, string placeId = null, bool displayCoordinates = true, bool trimUser = false, bool includeEntities = true) { if (String.IsNullOrEmpty(status)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "status", status }, { "display_coordinates", displayCoordinates ? "true" : "false" }, { "trim_user", trimUser ? "true" : "false" }, { "include_entities", includeEntities ? "true" : "false" } }; if (!string.IsNullOrEmpty(inReplyToStatusId)) { postData.Add("in_reply_to_status_id", inReplyToStatusId); } if (!double.IsNaN(latitude)) { postData.Add("lat", latitude.ToString("G", CultureInfo.InvariantCulture)); } if (!double.IsNaN(longitude)) { postData.Add("long", longitude.ToString("G", CultureInfo.InvariantCulture)); } if (!string.IsNullOrEmpty(placeId)) { postData.Add("place_id", placeId); } var uriBuilder = new UriBuilder(this.CommandBaseUri); uriBuilder.Path += "/update.json"; var response = this.TwitterApi.ExecuteAuthenticatedRequest(uriBuilder.Uri, HttpMethod.Post, postData); var twitterTweet = TwitterObject.Parse <TwitterTweet>(response); return(twitterTweet); }
private TwitterList AddRemoveMembers(string method, string listId, string slug, string ownerId, string ownerScreenName, IEnumerable <string> userIds, IEnumerable <string> screenNames) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string>(); if (!String.IsNullOrEmpty(listId)) { postData.Add("list_id", listId); } if (!String.IsNullOrEmpty(slug)) { postData.Add("slug", slug); } if (!String.IsNullOrEmpty(ownerId)) { postData.Add("owner_id", ownerId); } if (!String.IsNullOrEmpty(ownerScreenName)) { postData.Add("owner_screen_name", ownerScreenName); } if (userIds != null) { postData.Add("user_id", String.Join(",", userIds)); } if (screenNames != null) { postData.Add("screen_name", String.Join(",", screenNames)); } var uri = new Uri(this.CommandBaseUri + method); TwitterList list = null; try { var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); list = TwitterObject.Parse <TwitterList>(response); } catch (TwitterException e) { if (e.StatusCode != HttpStatusCode.BadRequest) { throw; } } return(list); }
/// <summary> /// Updates the authenticating user's profile image. /// </summary> /// <param name="fileName"></param> /// <param name="includeEntities"></param> /// <param name="skipStatus"></param> /// <returns></returns> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="TwitterException"></exception> public TwitterUser UpdateProfileImage(string fileName, bool includeEntities = true, bool skipStatus = false) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } if (String.IsNullOrEmpty(fileName)) { throw new ArgumentException(); } var imageType = new[] { ".GIF", ".JPG", ".JPEG", ".PNG" }; if (!imageType.Contains(Path.GetExtension(fileName), StringComparer.OrdinalIgnoreCase)) { throw new ArgumentException("Invalid image format.", "fileName"); } var fileInfo = new FileInfo(fileName); if (!fileInfo.Exists) { throw new ArgumentException("The specified file does not exist.", "fileName"); } if (fileInfo.Length > ProfileImageSize) { throw new TwitterException("The size of the image file must be less than 700KB."); } var data = new byte[fileInfo.Length]; using (var fs = fileInfo.OpenRead()) { fs.Read(data, 0, data.Length); } var postData = new Dictionary <string, object> { { "image", Convert.ToBase64String(data) }, { "include_entities", includeEntities ? "true" : "false" }, { "skip_status", skipStatus ? "true" : "false" } }; var uri = new Uri(this.CommandBaseUri + "/update_profile_image.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequestForMultipartFormData(uri, postData); var twitterUser = TwitterObject.Parse <TwitterUser>(response); return(twitterUser); }
public TwitterAccountSettings RetrieveAccountSettings() { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var uri = new Uri(this.CommandBaseUri + "/settings.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null); var settings = TwitterObject.Parse <TwitterAccountSettings>(response); return(settings); }
/// <summary> /// Updates the authenticating user's settings. /// </summary> /// <param name="trendLocationId"></param> /// <param name="sleepTimeEnabled"></param> /// <param name="startSleepTime"></param> /// <param name="endSleepTime"></param> /// <param name="timeZone">The time zone dates and times should be displayed in for the user.</param> /// <param name="language"> /// The language which Twitter should render in for this user. The language must be specified by /// the appropriate two letter ISO 639-1 representation. /// </param> /// <returns></returns> /// <remarks> /// While all parameters for this method are optional, at least one or more should be provided when executing /// this request. /// </remarks> public TwitterAccountSettings UpdateAccountSettings(string trendLocationId = null, bool?sleepTimeEnabled = null, string startSleepTime = null, string endSleepTime = null, string timeZone = null, string language = null) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string>(); if (!String.IsNullOrWhiteSpace(trendLocationId)) { postData.Add("trend_location_woeid", trendLocationId); } if (sleepTimeEnabled.HasValue) { postData.Add("sleep_time_enabled", sleepTimeEnabled.Value ? "true" : "false"); } if (!String.IsNullOrWhiteSpace(startSleepTime)) { postData.Add("start_sleep_time", startSleepTime); } if (!String.IsNullOrWhiteSpace(endSleepTime)) { postData.Add("end_sleep_time", endSleepTime); } if (!String.IsNullOrWhiteSpace(timeZone)) { postData.Add("time_zone", timeZone); } if (!String.IsNullOrWhiteSpace(language)) { postData.Add("lang", language); } if (postData.Count == 0) { throw new ArgumentException("While all parameters for this method are optional, " + "at least one or more should be provided when executing this request."); } var uri = new Uri(this.CommandBaseUri + "/settings.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var settings = TwitterObject.Parse <TwitterAccountSettings>(response); return(settings); }
/// <summary> /// Returns an array of numeric user ids the authenticating user is blocking. /// </summary> /// <param name="cursor"></param> /// <returns></returns> public TwitterCursorPagedIdCollection RetrieveIdsOfBlockedUsers(string cursor = "-1") { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var uri = new Uri(this.CommandBaseUri + String.Format("/blocking/ids.json?cursor={0}", !String.IsNullOrEmpty(cursor) ? cursor : "-1")); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null); var ids = TwitterObject.Parse <TwitterCursorPagedIdCollection>(response); return(ids); }
/// <summary> /// Returns tweets that match a specified query. /// </summary> /// <param name="q"></param> /// <param name="searchCommandOptions"></param> /// <returns></returns> public TwitterSearch Search(string q, SearchOptions searchCommandOptions) { if (String.IsNullOrEmpty(q)) { throw new ArgumentException(); } var uri = new Uri(this.CommandBaseUri + String.Format(".json?q={0}{1}", q, searchCommandOptions != null ? "&" + searchCommandOptions : "")); var response = this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var search = TwitterObject.Parse <TwitterSearch>(response); return(search); }
/// <summary> /// Access the users in a given category of the Twitter suggested dm list. /// It is recommended that end clients cache this data for no more than one hour. /// </summary> /// <param name="slug">The short name of list or a category.</param> /// <param name="language"></param> /// <returns></returns> public TwitterSuggestedUserCategory RetrieveSuggestionCategoryWithMembers(string slug, string language = null) { if (String.IsNullOrEmpty(slug)) { throw new ArgumentException(); } var queryString = String.IsNullOrEmpty(language) ? String.Empty : String.Format("?lang={0}", language); var uri = new Uri(this.CommandBaseUri + String.Format("/suggestions/{0}.json{1}", slug, queryString)); var response = this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var category = TwitterObject.Parse <TwitterSuggestedUserCategory>(response); return(category); }
private TwitterUser BlockUnblockUser(string method, string screenName, string userId, bool includeEntities, bool skipStatus) { if (String.IsNullOrEmpty(screenName) && String.IsNullOrEmpty(userId)) { throw new ArgumentException("A user id or screen name must be provided."); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "include_entities", includeEntities.ToString().ToLowerInvariant() }, { "skip_status", skipStatus.ToString().ToLowerInvariant() } }; if (!String.IsNullOrEmpty(userId)) { postData.Add("user_id", userId); } if (!String.IsNullOrEmpty(screenName)) { postData.Add("screen_name", screenName); } var uri = new Uri(this.CommandBaseUri + method); TwitterUser user = null; try { var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); user = TwitterObject.Parse <TwitterUser>(response); } catch (TwitterException e) { if (e.StatusCode != HttpStatusCode.NotFound) { throw; } } return(user); }
/// <summary> /// Returns if the authenticating user is blocking a target user. /// </summary> /// <param name="screenName"></param> /// <param name="userId"></param> /// <param name="includeEntities"></param> /// <param name="skipStatus"></param> /// <returns>Returns the blocked user if a block exists. Otherwise, null.</returns> public TwitterUser IsBlocked(string screenName, string userId = null, bool includeEntities = true, bool skipStatus = false) { if (String.IsNullOrEmpty(screenName) && String.IsNullOrEmpty(userId)) { throw new ArgumentException("A user id or screen name must be provided."); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var queryBuilder = new StringBuilder(); queryBuilder.AppendFormat("?include_entities={0}&skip_status={1}&", includeEntities ? "true" : "false", skipStatus ? "true" : "false"); if (!String.IsNullOrEmpty(screenName)) { queryBuilder.AppendFormat("screen_name={0}&", screenName); } if (!String.IsNullOrEmpty(userId)) { queryBuilder.AppendFormat("&user_id={0}", userId); } var uri = new Uri(this.CommandBaseUri + String.Format("/exists.json{0}", queryBuilder.ToString().TrimEnd('&'))); TwitterUser user = null; try { var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null); user = TwitterObject.Parse <TwitterUser>(response); } catch (TwitterException e) { if (e.StatusCode != HttpStatusCode.NotFound) { throw; } } return(user); }
private TwitterList RetrieveUserCreatedList(string listId, string slug, string ownerScreenName, string ownerId) { var queryBuilder = new StringBuilder(); queryBuilder.Append("?"); if (!String.IsNullOrEmpty(listId)) { queryBuilder.AppendFormat("list_id={0}&", listId); } if (!String.IsNullOrEmpty(slug)) { queryBuilder.AppendFormat("slug={0}&", slug); } if (!String.IsNullOrEmpty(ownerId)) { queryBuilder.AppendFormat("owner_id={0}&", ownerId); } if (!String.IsNullOrEmpty(ownerScreenName)) { queryBuilder.AppendFormat("owner_screen_name={0}&", ownerScreenName); } var uri = new Uri(this.CommandBaseUri + String.Format("/show.json{0}", queryBuilder.ToString().TrimEnd('&'))); TwitterList list = null; try { var response = this.TwitterApi.Authenticated ? this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null) : this.TwitterApi.ExecuteUnauthenticatedRequest(uri); list = TwitterObject.Parse <TwitterList>(response); } catch (TwitterException e) { if (e.StatusCode == HttpStatusCode.NotFound) { throw; } } return(list); }
/// <summary> /// Sets values that users are able to set under the "Account" tab of their settings page. /// Only the parameters specified will be updated. /// </summary> /// <param name="name">Full name associated with the profile. Maximum of 20 characters.</param> /// <param name="url">URL associated with the profile.</param> /// <param name="location">The city or country describing where the user of the account is located. </param> /// <param name="description">A description of the user owning the account. Maximum of 160 characters.</param> /// <param name="includeEntities"></param> /// <param name="skipStatus"></param> /// <returns>Returns updated user if successful. Otherwise, null.</returns> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="TwitterException"></exception> public TwitterUser UpdateProfile(string name = null, Uri url = null, string location = null, string description = null, bool includeEntities = true, bool skipStatus = false) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } if (url != null) { if (url.Scheme != Uri.UriSchemeHttp && url.Scheme != Uri.UriSchemeHttps) { throw new ArgumentException("Invalid uri.", "url"); } } var postData = new Dictionary <string, string> { { "include_entities", includeEntities ? "true" : "false" }, { "skip_status", skipStatus ? "true" : "false" } }; if (name != null) { postData.Add("name", name); } if (url != null) { postData.Add("url", url.ToString()); } if (location != null) { postData.Add("location", location); } if (description != null) { postData.Add("description", description); } var uri = new Uri(this.CommandBaseUri + "/update_profile.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var twitterUser = TwitterObject.Parse <TwitterUser>(response); return(twitterUser); }
private TwitterList UpdateList(string listId, string slug, string ownerId, string ownerScreenName, string name, TwitterListMode mode, string description) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "mode", mode.ToString().ToLowerInvariant() } }; if (!String.IsNullOrEmpty(listId)) { postData.Add("list_id", listId); } if (!String.IsNullOrEmpty(slug)) { postData.Add("slug", slug); } if (!String.IsNullOrEmpty(ownerId)) { postData.Add("owner_id", ownerId); } if (!String.IsNullOrEmpty(ownerScreenName)) { postData.Add("owner_screen_name", ownerScreenName); } if (!String.IsNullOrEmpty(name)) { postData.Add("name", name); } if (!String.IsNullOrEmpty(description)) { postData.Add("description", description); } var uri = new Uri(this.CommandBaseUri + "/update.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var list = TwitterObject.Parse <TwitterList>(response); return(list); }
private TwitterList DestroyList(string listId, string slug, string ownerId, string ownerScreenName) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string>(); if (!String.IsNullOrEmpty(listId)) { postData.Add("list_id", listId); } if (!String.IsNullOrEmpty(slug)) { postData.Add("slug", slug); } if (!String.IsNullOrEmpty(ownerId)) { postData.Add("owner_id", ownerId); } if (!String.IsNullOrEmpty(ownerScreenName)) { postData.Add("owner_screen_name", ownerScreenName); } var uri = new Uri(this.CommandBaseUri + "/destroy.json"); TwitterList list = null; try { var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); list = TwitterObject.Parse <TwitterList>(response); } catch (TwitterException e) { if (e.StatusCode != HttpStatusCode.NotFound) { throw; } } return(list); }
private TwitterCursorPagedIdCollection RetrieveIdsForFollowingRequests(string cursor, string type) { if (String.IsNullOrEmpty(cursor)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var uri = new Uri(this.CommandBaseUri + String.Format("/{0}.json?cursor={1}", type, cursor)); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null); var ids = TwitterObject.Parse <TwitterCursorPagedIdCollection>(response); return(ids); }
/// <summary> /// Sets one or more hex values that control the color scheme of the authenticating /// user's profile page on twitter.com. /// </summary> /// <param name="backgroundColor">Profile background color.</param> /// <param name="linkColor">Profile link color.</param> /// <param name="sidebarBorderColor">Profile sidebar's border color.</param> /// <param name="sidebarFillColor">Profile sidebar's background color.</param> /// <param name="textColor">Profile text color.</param> /// <param name="includeEntities"></param> /// <param name="skipStatus"></param> /// <returns></returns> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="TwitterException"></exception> public TwitterUser UpdateProfileColors(TwitterColor?backgroundColor = null, TwitterColor?linkColor = null, TwitterColor?sidebarBorderColor = null, TwitterColor?sidebarFillColor = null, TwitterColor?textColor = null, bool includeEntities = true, bool skipStatus = false) { if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var postData = new Dictionary <string, string> { { "include_entities", includeEntities ? "true" : "false" }, { "skip_status", skipStatus ? "true" : "false" } }; if (backgroundColor.HasValue) { postData.Add("profile_background_color", backgroundColor.Value.ToString()); } if (linkColor.HasValue) { postData.Add("profile_link_color", linkColor.Value.ToString()); } if (sidebarBorderColor.HasValue) { postData.Add("profile_sidebar_border_color", sidebarBorderColor.Value.ToString()); } if (sidebarFillColor.HasValue) { postData.Add("profile_sidebar_fill_color", sidebarFillColor.Value.ToString()); } if (textColor.HasValue) { postData.Add("profile_text_color", textColor.Value.ToString()); } var uri = new Uri(this.CommandBaseUri + "/update_profile_colors.json"); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, postData); var twitterUser = TwitterObject.Parse <TwitterUser>(response); return(twitterUser); }
/// <summary> /// Returns detailed information about the relationship between two users. /// </summary> /// <param name="sourceScreenName"></param> /// <param name="targetScreenName"></param> /// <param name="sourceId"></param> /// <param name="targetId"></param> /// <returns></returns> public TwitterRelationship Show(string sourceScreenName, string targetScreenName, string sourceId = null, string targetId = null) { if (String.IsNullOrEmpty(sourceId) && String.IsNullOrEmpty(sourceScreenName)) { throw new ArgumentException("Either a sourceId or sourceScreenName is required for this method."); } if (String.IsNullOrEmpty(targetId) && String.IsNullOrEmpty(targetScreenName)) { throw new ArgumentException("Either a targetId or targetScreenName is required for this method."); } var queryBuilder = new StringBuilder(); if (!String.IsNullOrEmpty(sourceId)) { queryBuilder.AppendFormat("source_id={0}&", sourceId); } if (!String.IsNullOrEmpty(sourceScreenName)) { queryBuilder.AppendFormat("source_screen_name={0}&", sourceScreenName); } if (!String.IsNullOrEmpty(targetId)) { queryBuilder.AppendFormat("target_id={0}&", targetId); } if (!String.IsNullOrEmpty(targetScreenName)) { queryBuilder.AppendFormat("target_screen_name={0}", targetScreenName); } var uri = new Uri(this.CommandBaseUri + String.Format("/show.json?{0}", queryBuilder.ToString().TrimEnd('&'))); var response = this.TwitterApi.Authenticated ? this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null) : this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var jsonObj = JObject.Parse(response); var rel = TwitterObject.Parse <TwitterRelationship>(jsonObj["relationship"].ToString()); return(rel); }
/// <summary> /// Destroys a saved search for the authenticating user. /// </summary> /// <param name="id"></param> /// <returns></returns> public TwitterSavedSearch Destroy(string id) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var uri = new Uri(this.CommandBaseUri + String.Format("/destroy/{0}.json", id)); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Post, null); var savedSeach = TwitterObject.Parse <TwitterSavedSearch>(response); return(savedSeach); }
/// <summary> /// Returns a single direct message, specified by an id parameter. /// </summary> /// <param name="id"></param> /// <returns></returns> public TwitterDirectMessage Show(string id) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException(); } if (!this.TwitterApi.Authenticated) { throw new InvalidOperationException("Authentication required."); } var uri = new Uri(this.CommandBaseUri + String.Format("/show/{0}.json", id)); var response = this.TwitterApi.ExecuteAuthenticatedRequest(uri, HttpMethod.Get, null); var dm = TwitterObject.Parse <TwitterDirectMessage>(response); return(dm); }
public bool CreateControllerPayload(string[] args = null) { Thread.BeginCriticalRegion(); if (args != null) { try { TwitterController = new TwitterObject(args[0], args[1], args[2], args[3]); Topic = args[4]; for( int i = 0; i < args.Length; i++) { //Ignore the first 4 arguments. if (args[i] == args[0] || args[i] == args[1] || args[i] == args[2] || args[i] == args[3] || args[i] == args[4]) continue; Targets.Add(args[i]); } //user can now do this. isSafe = true; return true; } catch( Exception Error ) { ConsoleExtender.Error(Error); return false; } } Thread.EndCriticalRegion(); return false; }