/// <summary> /// Removes the uploaded profile banner for the authenticating user. Returns HTTP 200 upon success. /// </summary> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner </remarks> public static async Task <TwitterSuccess> DeleteProfileBanner(this IUserSession session) { var parameters = new TwitterParametersCollection(); return(await session.PostAsync(TwitterApi.Resolve("/1.1/account/remove_profile_banner.json"), parameters) .ContinueWith(c => c.MapToTwitterSuccess())); }
/// <summary> /// Removes the uploaded profile banner for the authenticating user. Returns HTTP 20x upon success. /// </summary> /// <param name="fileName">file name for upload</param> /// <param name="imageContentStream">Stream of image content</param> /// <param name="bannerWidth">The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.</param> /// <param name="bannerHeight">The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.</param> /// <param name="bannerLeftOffset">The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.</param> /// <param name="bannerTopOffset">The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.</param> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner </remarks> public static async Task <TwitterSuccess> ChangeProfileBanner(this IUserSession session, string fileName, Stream imageContentStream, int bannerWidth = 0, int bannerHeight = 0, int bannerLeftOffset = 0, int bannerTopOffset = 0) { var parameters = new TwitterParametersCollection(); if (bannerWidth != 0) { parameters.Add("width", bannerWidth.ToString()); } if (bannerHeight != 0) { parameters.Add("height", bannerWidth.ToString()); } if (bannerLeftOffset != 0) { parameters.Add("offset_left", bannerWidth.ToString()); } if (bannerTopOffset != 0) { parameters.Add("offset_top", bannerWidth.ToString()); } return(await session.PostFileAsync(TwitterApi.Resolve("/1.1/account/update_profile_banner.json"), parameters, fileName, "banner", srImage : imageContentStream) .ContinueWith(c => c.MapToTwitterSuccess())); }
/// <summary> /// Updates the authenticating user's profile image. /// </summary> /// <param name="fileName">file name for upload</param> /// <param name="imageContent">byte array of image content</param> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image </remarks> public static async Task <User> ChangeAccountProfileImage(this IUserSession session, string fileName, byte[] imageContent) { var parameters = new TwitterParametersCollection(); return(await session.PostFileAsync(TwitterApi.Resolve("/1.1/account/update_profile_image.json"), parameters, fileName, "image", imageContent) .ContinueWith(c => c.MapToSingle <User>())); }
public TwitterParametersCollection ChangeSearchParameters(string track = null, string follow = null, string locations = null, string filterlevel = "none", string language = "en") { var parameters = new TwitterParametersCollection(); parameters.Create(stall_warnings: false, delimited: false); if (track != null) { parameters.CreateCommaDelimitedList("track", new List <string> { track }); } if (follow != null) { parameters.CreateCommaDelimitedList("follow", new List <string> { follow }); } if (locations != null) { parameters.CreateCommaDelimitedList("locations", new List <string> { locations }); } parameters.Add("filter_level", filterlevel); parameters.Add("language", language); return(parameters); }
/// <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="profileUrl">URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.</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> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/account/update_profile </remarks> public static async Task <User> ChangeAccountProfile(this IUserSession session, string name = "", string profileUrl = "", string location = "", string description = "") { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, skip_status: true); // first 20 chars if (!string.IsNullOrWhiteSpace(name)) { parameters.Add("name", name.TrimAndTruncate(20)); } // first 100 chars if (!string.IsNullOrWhiteSpace(profileUrl)) { parameters.Add("purl", profileUrl.TrimAndTruncate(100)); } // first 30 chars if (!string.IsNullOrWhiteSpace(location)) { parameters.Add("location", location.TrimAndTruncate(30)); } // first 160 chars if (!string.IsNullOrWhiteSpace(description)) { parameters.Add("description", description.TrimAndTruncate(160)); } return(await session.PostAsync(TwitterApi.Resolve("/1.1/account/update_profile.json"), parameters) .ContinueWith(c => c.MapToSingle <User>())); }
/// <summary> /// Returns the locations that Twitter has trending topic information for. /// </summary> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/trends/available </remarks> public static async Task <TwitterResponseCollection <TrendsAvailableLocationsResponse> > GetTrendsAvailableLocations(this ITwitterSession session) { var parameters = new TwitterParametersCollection(); return(await session.GetAsync(TwitterApi.Resolve("/1.1/trends/available.json"), parameters) .ContinueWith(c => c.MapToMany <TrendsAvailableLocationsResponse>())); }
/// <summary> /// Returns detailed information about the relationship between two arbitrary users. /// </summary> /// <param name="sourceScreenName">The user_id of the subject user.</param> /// <param name="sourceId">The screen_name of the subject user.</param> /// <param name="targetId">The user_id of the target user.</param> /// <param name="targetScreenName">The screen_name of the target user.</param> /// <returns></returns> /// <remarks> ref: https://api.twitter.com/1.1/friendships/show.json </remarks> public async static Task <UserStatus> GetFriendship(this IUserSession session, string sourceScreenName = "", string targetScreenName = "", int sourceId = 0, int targetId = 0) { var parameters = new TwitterParametersCollection(); if (!string.IsNullOrWhiteSpace(sourceScreenName)) { parameters.Add("source_screen_name", sourceScreenName); } if (sourceId != 0) { parameters.Add("source_id", sourceId.ToString()); } if (!string.IsNullOrWhiteSpace(targetScreenName)) { parameters.Add("target_screen_name", targetScreenName); } if (targetId != 0) { parameters.Add("target_id", targetId.ToString()); } if (parameters.EnsureAllArePresent(new [] { "source_screen_name", "source_id", "target_screen_name", "target_id" }).IsFalse()) { return(session.MapParameterError <UserStatus>( "source_screen_name, source_id, target_screen_name and target_id are all required")); } return(await session.PostAsync(TwitterApi.Resolve("/1.1/friendships/show.json"), parameters) .ContinueWith(c => c.MapToSingle <UserStatus>())); }
/// <summary> /// Returns the authenticated user's saved search queries. /// </summary> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/saved_searches/list </remarks> public async static Task <TwitterResponseCollection <SavedSearch> > GetSavedSearches(this IUserSession session) { var parameters = new TwitterParametersCollection(); return(await session.GetAsync(TwitterApi.Resolve("/1.1/saved_searches/list.json"), parameters) .ContinueWith(c => c.MapToMany <SavedSearch>())); }
/// <summary> /// Returns the locations that Twitter has trending topic information for. /// </summary> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/trends/available </remarks> public static async Task<TwitterResponseCollection<TrendsAvailableLocationsResponse>> GetTrendsAvailableLocations(this ITwitterSession session) { var parameters = new TwitterParametersCollection(); return await session.GetAsync(TwitterApi.Resolve("/1.1/trends/available.json"), parameters) .ContinueWith(c => c.MapToMany<TrendsAvailableLocationsResponse>()); }
/// <summary> /// Returns detailed information about the relationship between two arbitrary users. /// </summary> /// <param name="sourceScreenName">The user_id of the subject user.</param> /// <param name="sourceId">The screen_name of the subject user.</param> /// <param name="targetId">The user_id of the target user.</param> /// <param name="targetScreenName">The screen_name of the target user.</param> /// <returns></returns> /// <remarks> ref: https://api.twitter.com/1.1/friendships/show.json </remarks> public async static Task <UserStatus> GetFriendship(this ITwitterSession session, string sourceScreenName = "", string targetScreenName = "", int sourceId = 0, int targetId = 0) { var parameters = new TwitterParametersCollection(); if (!string.IsNullOrWhiteSpace(sourceScreenName)) { parameters.Add("source_screen_name", sourceScreenName); } if (sourceId != 0) { parameters.Add("source_id", sourceId.ToString()); } if (!string.IsNullOrWhiteSpace(targetScreenName)) { parameters.Add("target_screen_name", targetScreenName); } if (targetId != 0) { parameters.Add("target_id", targetId.ToString()); } return(await session.GetAsync(TwitterApi.Resolve("/1.1/friendships/show.json"), parameters) .ContinueWith(c => c.MapToSingle <UserStatus>())); }
/// <summary> /// Returns settings (including current trend, geo and sleep time information) for the authenticating user. /// </summary> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/account/settings </remarks> public static async Task <AccountSettings> GetAccountSettings(this IUserSession session) { var parameters = new TwitterParametersCollection(); return(await session.GetAsync(TwitterApi.Resolve("/1.1/account/settings.json"), parameters) .ContinueWith(c => c.MapToSingle <AccountSettings>())); }
/// <summary> /// Access the users in a given category of the Twitter suggested user list. /// </summary> /// <param name="slug">The short name of list or a category returned by GetSuggestedList</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug </remarks> public static async Task<SuggestedUsers> GetSuggestedUsers(this ITwitterSession session, string slug) { var parameters = new TwitterParametersCollection(); var url = TwitterApi.Resolve("/1.1/users/suggestions/{0}.json", slug); return await session.GetAsync(url, parameters) .ContinueWith(c => c.MapToSingle<SuggestedUsers>()); }
/// <summary> /// Returns the current configuration used by Twitter including twitter.com slugs which are not usernames, maximum photo resolutions, and t.co URL lengths. /// </summary> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/rest/reference/get/help/configuration </remarks> public async static Task <Configuration> GetConfiguration(this IUserSession session) { var parameters = new TwitterParametersCollection(); parameters.Create(); return(await session.GetAsync(TwitterApi.Resolve("/1.1/help/configuration.json"), parameters).ContinueWith(c => c.MapToSingle <Configuration>())); }
/// <summary> /// Deletes tweet of a given id /// </summary> /// <param name="tweetId">ID of the tweet to delete</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid </remarks> public async static Task<TwitterSuccess> DeleteTweet(this IUserSession session, string tweetId) { var parameters = new TwitterParametersCollection(); var url = TwitterApi.Resolve("/1.1/statuses/destroy/{0}.json", tweetId); return await session.PostAsync(url, parameters) .ContinueWith(c => c.MapToTwitterSuccess()); }
/// <summary> /// Access to Twitter's suggested user list. This returns the list of suggested user categories. /// </summary> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/users/suggestions </remarks> public static async Task <TwitterResponseCollection <SuggestedUsers> > GetSuggestedLists(this ITwitterSession session) { var parameters = new TwitterParametersCollection(); return(await session.GetAsync(TwitterApi.Resolve("/1.1/users/suggestions.json"), parameters) .ContinueWith(c => c.MapToMany <SuggestedUsers>())); }
/// <summary> /// Returns the most recent tweets authored by the authenticating user that have been retweeted by others. /// </summary> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID.</param> /// <param name="count">Specifies the number of records to retrieve. Must be less than or equal to 100. If omitted, 20 will be assumed.</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me </remarks> public async static Task<TwitterResponseCollection<Tweet>> GetRetweetsOfMe(this IUserSession session, long sinceId = 0, long maxId = 0, int count = 20) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, include_rts: true, count: count, since_id: sinceId, max_id: maxId); return await session.GetAsync(TwitterApi.Resolve("/1.1/statuses/retweets_of_me.json"), parameters) .ContinueWith(c => c.MapToMany<Tweet>()); }
/// <summary> /// Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid. /// </summary> /// <returns></returns> public static async Task<User> GetVerifyCredentials(this IUserSession session) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true); return await session.GetAsync(TwitterApi.Resolve("/1.1/account/verify_credentials.json"), parameters) .ContinueWith(c => c.MapToSingle<User>()); }
/// <summary> /// Deletes tweet of a given id /// </summary> /// <param name="tweetId">ID of the tweet to delete</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid </remarks> public async static Task <TwitterSuccess> DeleteTweet(this IUserSession session, string tweetId) { var parameters = new TwitterParametersCollection(); var url = TwitterApi.Resolve("/1.1/statuses/destroy/{0}.json", tweetId); return(await session.PostAsync(url, parameters) .ContinueWith(c => c.MapToTwitterSuccess())); }
/// <summary> /// Retrieve the information for the saved search represented by the given id. /// </summary> /// <param name="id">The ID of the saved search.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/%3Aid </remarks> public async static Task <SavedSearch> GetSaveASearch(this IUserSession session, string id) { var parameters = new TwitterParametersCollection(); var url = TwitterApi.Resolve("/1.1/saved_searches/show/{0}.json", id); return(await session.GetAsync(url, parameters) .ContinueWith(c => c.MapToSingle <SavedSearch>())); }
/// <summary> /// Creates a saved search /// </summary> /// <param name="SavedSearchId">The ID of the saved search.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/%3Aid </remarks> public async static Task <SavedSearch> DeleteSavedSearch(this IUserSession session, string SavedSearchId) { var parameters = new TwitterParametersCollection(); var savedSearch = TwitterApi.Resolve("/1.1/saved_searches/destroy/{0}.json", SavedSearchId); return(await session.PostAsync(savedSearch, parameters) .ContinueWith(c => c.MapToSingle <SavedSearch>())); }
/// <summary> /// Retweets a tweet /// </summary> /// <param name="tweet">The tweet to retweet</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid </remarks> public async static Task <Tweet> Retweet(this IUserSession session, Tweet tweet) { var parameters = new TwitterParametersCollection(); var path = TwitterApi.Resolve("/1.1/statuses/retweet/{0}.json", tweet.Id); return(await session.PostAsync(path, parameters) .ContinueWith(c => c.MapToSingle <Tweet>())); }
/// <summary> /// Returns a direct message sent to the authenticating user. /// </summary> /// <param name="Id">ID of direct message to return</param> /// <returns>(awaitable) Get A DirectMessage sent/received the session's authenticated user</returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/get/direct_messages/show </remarks> public async static Task<DirectMessage> GetDirectMessageSingle(this IUserSession session, long Id) { var parameters = new TwitterParametersCollection(); parameters.Create(id: Id, full_text:true); return await session.GetAsync(TwitterApi.Resolve("/1.1/direct_messages/show.json"), parameters) .ContinueWith(c => c.MapToSingle<DirectMessage>()); }
/// <summary> /// Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters. /// </summary> /// <param name="userId">The ID of the user for whom to return results for.</param> /// <param name="screenName">The screen name of the user for whom to return results for.</param> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID.</param> /// <param name="count">Specifies the number of tweets to try and retrieve, up to a maximum of 200 per distinct request</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID.</param> /// <param name="excludeReplies">This parameter will prevent replies from appearing in the returned timeline. </param> /// <param name="includeRetweets">When set to false, the timeline will strip any native retweets</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline </remarks> public async static Task<TwitterResponseCollection<Tweet>> GetUserTimeline(this ITwitterSession session, string screenName = "", long userId = 0, long sinceId = 0, long maxId = 0, int count = 200, bool excludeReplies = true, bool includeRetweets = true) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, include_rts: true, count: count, since_id: sinceId, max_id: maxId, screen_name:screenName); return await session.GetAsync(TwitterApi.Resolve("/1.1/statuses/user_timeline.json"), parameters) .ContinueWith(c => c.MapToMany<Tweet>()); }
/// <summary> /// Access the users in a given category of the Twitter suggested user list. /// </summary> /// <param name="slug">The short name of list or a category returned by GetSuggestedList</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug </remarks> public static async Task <SuggestedUsers> GetSuggestedUsers(this ITwitterSession session, string slug) { var parameters = new TwitterParametersCollection(); var url = TwitterApi.Resolve("/1.1/users/suggestions/{0}.json", slug); return(await session.GetAsync(url, parameters) .ContinueWith(c => c.MapToSingle <SuggestedUsers>())); }
/// <summary> /// Returns a direct message sent to the authenticating user. /// </summary> /// <param name="Id">ID of direct message to return</param> /// <returns>(awaitable) Get A DirectMessage sent/received the session's authenticated user</returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/get/direct_messages/show </remarks> public async static Task <DirectMessage> GetDirectMessageSingle(this IUserSession session, long Id) { var parameters = new TwitterParametersCollection(); parameters.Create(id: Id); return(await session.GetAsync(TwitterApi.Resolve("/1.1/direct_messages/show.json"), parameters) .ContinueWith(c => c.MapToSingle <DirectMessage>())); }
/// <summary> /// Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters. /// </summary> /// <param name="userId">The ID of the user for whom to return results for.</param> /// <param name="screenName">The screen name of the user for whom to return results for.</param> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID.</param> /// <param name="count">Specifies the number of tweets to try and retrieve, up to a maximum of 200 per distinct request</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID.</param> /// <param name="excludeReplies">This parameter will prevent replies from appearing in the returned timeline. </param> /// <param name="includeRetweets">When set to false, the timeline will strip any native retweets</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline </remarks> public async static Task <TwitterResponseCollection <Tweet> > GetUserTimeline(this ITwitterSession session, string screenName = "", long userId = 0, long sinceId = 0, long maxId = 0, int count = 200, bool excludeReplies = true, bool includeRetweets = true) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, include_rts: true, count: count, since_id: sinceId, max_id: maxId, screen_name: screenName); return(await session.GetAsync(TwitterApi.Resolve("/1.1/statuses/user_timeline.json"), parameters) .ContinueWith(c => c.MapToMany <Tweet>())); }
/// <summary> /// Returns the most recent tweets authored by the authenticating user that have been retweeted by others. /// </summary> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID.</param> /// <param name="count">Specifies the number of records to retrieve. Must be less than or equal to 100. If omitted, 20 will be assumed.</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me </remarks> public async static Task <TwitterResponseCollection <Tweet> > GetRetweetsOfMe(this IUserSession session, long sinceId = 0, long maxId = 0, int count = 20) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, include_rts: true, count: count, since_id: sinceId, max_id: maxId); return(await session.GetAsync(TwitterApi.Resolve("/1.1/statuses/retweets_of_me.json"), parameters) .ContinueWith(c => c.MapToMany <Tweet>())); }
/// <summary> /// Deletes a sent direct message /// </summary> /// <param name="Id">ID of the direct message to delete</param> /// <returns>TwitterSuccess (true) if deletion worked</returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy </remarks> public async static Task <TwitterSuccess> DeleteDirectMessage(this IUserSession session, long Id) { var parameters = new TwitterParametersCollection(); parameters.Create(id: Id); return(await session.PostAsync(TwitterApi.Resolve("/1.1/direct_messages/destroy.json"), parameters) .ContinueWith(c => c.MapToTwitterSuccess())); }
/// <summary> /// Returns the most recent direct messages sent by the authenticating user. /// </summary> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID</param> /// <param name="count">Specifies the number of direct messages to try and retrieve, up to a maximum of 200</param> /// <returns>(awaitable) IEnumerable of DirectMessages Sent by the session's authenticated user</returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent </remarks> public async static Task<TwitterResponseCollection<DirectMessage>> GetDirectMessagesSent(this IUserSession session, long sinceId = 0, long maxId = 0, int count = 20) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, count: count, since_id: sinceId, max_id: maxId, full_text:true); return await session.GetAsync(TwitterApi.Resolve("/1.1/direct_messages/sent.json"), parameters) .ContinueWith(c => c.MapToMany<DirectMessage>()); }
/// <summary> /// Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user. /// </summary> /// <param name="cursor">default is first page (-1) otherwise provide starting point</param> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/friendships/incoming </remarks> public async static Task <FriendsFollowersIDsCursored> GetFriendshipRequestsIncoming(this IUserSession session, long cursor = -1) { var parameters = new TwitterParametersCollection(); parameters.Create(cursor: cursor); return(await session.GetAsync(TwitterApi.Resolve("/1.1/friendships/incoming.json"), parameters) .ContinueWith(t => t.MapToSingle <FriendsFollowersIDsCursored>())); }
/// <summary> /// Returns a collection of user objects that the authenticating user is blocking. /// </summary> /// <param name="cursor">Causes the list of blocked users to be broken into pages of no more than 5000 IDs at a time.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/blocks/list </remarks> public static async Task <UserListDetailedCursored> GetBlockList(this IUserSession session, long cursor = -1) { var parameters = new TwitterParametersCollection(); parameters.Create(cursor: cursor); return(await session.GetAsync(TwitterApi.Resolve("/1.1/blocks/list.json"), parameters) .ContinueWith(c => c.MapToSingle <UserListDetailedCursored>())); }
/// <summary> /// https://dev.twitter.com/docs/api/1.1/get/favorites/list /// Returns the count most recent Tweets favorited by the authenticating or specified user. /// If user_id and screen_name is left blank, current auth'd user favourites are returned /// Entities are always returned /// </summary> /// <param name="userId">The ID of the user for whom to return results for</param> /// <param name="screenName">The screen name of the user for whom to return results for</param> /// <param name="sinceId">Returns results with an ID greater than</param> /// <param name="count">Specifies the number of records to retrieve. Must be less than or equal to 200. Defaults to 20.</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified </param> /// <returns></returns> public async static Task<TwitterResponseCollection<Tweet>> GetFavourites(this ITwitterSession session, string screenName = "", int userId = 0, long sinceId = 0, long maxId = 0, int count = 20 ) { var parameters = new TwitterParametersCollection(); parameters.Create(count:count,include_entities:true,since_id:sinceId,max_id:maxId, user_id:userId, screen_name:screenName); var url = TwitterApi.Resolve("/1.1/favorites/list.json"); return await session.GetAsync(url, parameters) .ContinueWith(c => c.MapToMany<Tweet>()); }
/// <summary> /// Removes the specified member from the list. The authenticated user must be the list's owner to remove members from the list. /// </summary> /// <param name="listId">The numerical id of the list.</param> /// <param name="slug">You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.</param> /// <param name="userId">The ID of the user to remove from the list. Helpful for disambiguating when a valid user ID is also a valid screen name.</param> /// <param name="screenName">The screen name of the user for whom to remove from the list. Helpful for disambiguating when a valid screen name is also a user ID.</param> /// <param name="ownerScreenName">The screen name of the user who owns the list being requested by a slug.</param> /// <param name="ownerId">The user ID of the user who owns the list being requested by a slug.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy </remarks> public static async Task<TwitterSuccess> DeleteUserFromList(this IUserSession session, long listId = 0, string slug = "", long userId = 0, string screenName = "", string ownerScreenName = "", long ownerId = 0) { var parameters = new TwitterParametersCollection(); parameters.Create(list_id: listId, slug: slug, owner_id: ownerId, owner_screen_name: ownerScreenName, user_id: userId, screen_name: screenName); return await session.PostAsync(TwitterApi.Resolve("/1.1/lists/members/destroy"), parameters) .ContinueWith(c => c.MapToTwitterSuccess()); }
/// <summary> /// https://dev.twitter.com/docs/api/1.1/post/favorites/destroy /// Un-favourites a given tweet /// </summary> /// <param name="tweet">Tweet for to favourite</param> /// <returns></returns> public async static Task<Tweet> DeleteFavourite(this IUserSession session, Tweet tweet) { var parameters = new TwitterParametersCollection(); parameters.Create(id: tweet.Id); var url = TwitterApi.Resolve("/1.1/favorites/destroy.json"); return await session.PostAsync(url, parameters) .ContinueWith(c => c.MapToSingle<Tweet>()); }
/// <summary> /// Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid. /// </summary> /// <returns></returns> public static async Task <User> GetVerifyCredentials(this IUserSession session) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true); return(await session.GetAsync(TwitterApi.Resolve("/1.1/account/verify_credentials.json"), parameters) .ContinueWith(c => c.MapToSingle <User>())); }
/// <summary> /// Returns the members of the specified list. Private list members will only be shown if the authenticated user owns the specified list. /// </summary> /// <param name="listId">The numerical id of the list.</param> /// <param name="slug">You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.</param> /// <param name="ownerScreenName">The screen name of the user who owns the list being requested by a slug.</param> /// <param name="ownerId">The user ID of the user who owns the list being requested by a slug.</param> /// <param name="cursor">Breaks the results into pages.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/lists/members </remarks> public static async Task <UserListDetailedCursored> GetMembersOnList(this IUserSession session, long listId, string slug, string ownerScreenName = "", long ownerId = 0, long cursor = -1) { var parameters = new TwitterParametersCollection(); parameters.Create(list_id: listId, slug: slug, owner_id: ownerId, owner_screen_name: ownerScreenName, skip_status: true, include_entities: true, cursor: cursor); return(await session.GetAsync(TwitterApi.Resolve("/1.1/lists/members.json"), parameters) .ContinueWith(c => c.MapToSingle <UserListDetailedCursored>())); }
/// <summary> /// Returns the specified list. Private lists will only be shown if the authenticated user owns the specified list. /// </summary> /// <param name="listId">The numerical id of the list.</param> /// <param name="slug">You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.</param> /// <param name="ownerId">The user ID of the user who owns the list being requested by a slug.</param> /// <param name="ownerScreenName">The screen name of the user who owns the list being requested by a slug.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/lists/show </remarks> public static async Task <TwitterList> GetList(this ITwitterSession session, long listId, string slug, string ownerScreenName = "", long ownerId = 0) { var parameters = new TwitterParametersCollection(); parameters.Create(list_id: listId, slug: slug, owner_id: ownerId, owner_screen_name: ownerScreenName); return(await session.GetAsync(TwitterApi.Resolve("/1.1/lists/show.json"), parameters) .ContinueWith(c => c.MapToSingle <TwitterList>())); }
/// <summary> /// Returns the lists owned by the specified Twitter user. Private lists will only be shown if the authenticated user is also the owner of the lists. /// </summary> /// <param name="screenName"></param> /// <param name="userId"></param> /// <param name="count"></param> /// <param name="cursor"></param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/lists/ownerships </remarks> public static async Task <TwitterListCursored> GetListOwned(this ITwitterSession session, string screenName = "", long userId = 0, int count = 20, long cursor = -1) { var parameters = new TwitterParametersCollection(); parameters.Create(user_id: userId, screen_name: screenName, count: count, cursor: cursor); return(await session.GetAsync(TwitterApi.Resolve("/1.1/lists/ownerships.json"), parameters) .ContinueWith(c => c.MapToSingle <TwitterListCursored>())); }
/// <summary> /// Removes the specified member from the list. The authenticated user must be the list's owner to remove members from the list. /// </summary> /// <param name="listId">The numerical id of the list.</param> /// <param name="slug">You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.</param> /// <param name="userId">The ID of the user to remove from the list. Helpful for disambiguating when a valid user ID is also a valid screen name.</param> /// <param name="screenName">The screen name of the user for whom to remove from the list. Helpful for disambiguating when a valid screen name is also a user ID.</param> /// <param name="ownerScreenName">The screen name of the user who owns the list being requested by a slug.</param> /// <param name="ownerId">The user ID of the user who owns the list being requested by a slug.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy </remarks> public static async Task <TwitterSuccess> DeleteUserFromList(this IUserSession session, long listId = 0, string slug = "", long userId = 0, string screenName = "", string ownerScreenName = "", long ownerId = 0) { var parameters = new TwitterParametersCollection(); parameters.Create(list_id: listId, slug: slug, owner_id: ownerId, owner_screen_name: ownerScreenName, user_id: userId, screen_name: screenName); return(await session.PostAsync(TwitterApi.Resolve("/1.1/lists/members/destroy"), parameters) .ContinueWith(c => c.MapToTwitterSuccess())); }
/// <summary> /// Check if the specified user is a member of the specified list /// </summary> /// <param name="listId">The numerical id of the list.</param> /// <param name="slug">You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.</param> /// <param name="userId">The ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.</param> /// <param name="screenName">The screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.</param> /// <param name="ownerScreenName">The screen name of the user who owns the list being requested by a slug.</param> /// <param name="ownerId">The user ID of the user who owns the list being requested by a slug.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/lists/members/show </remarks> public static async Task <User> IsUserOnList(this ITwitterSession session, long listId, string slug = "", long userId = 0, string screenName = "", string ownerScreenName = "", long ownerId = 0) { var parameters = new TwitterParametersCollection(); parameters.Create(user_id: userId, screen_name: screenName, list_id: listId, slug: slug, owner_id: ownerId, owner_screen_name: ownerScreenName, skip_status: true, include_entities: true); return(await session.GetAsync(TwitterApi.Resolve("/1.1/lists/members/show.json"), parameters) .ContinueWith(c => c.MapToSingle <User>())); }
/// <summary> /// Returns the top 10 trending topics for a specific WOEID, if trending information is available for it. /// </summary> /// <param name="placeId">The Yahoo! Where On Earth ID of the location to return trending information for. Global information is available by using 1 as the WOEID.</param> /// <param name="exclude">If true will remove all hashtags from the trends list.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/trends/place </remarks> public static async Task<TwitterResponseCollection<TrendsForPlaceResponse>> GetTrendsForPlace(this ITwitterSession session, int placeId = 1, bool exclude = false) { var parameters = new TwitterParametersCollection {{"id",placeId.ToString()}}; if (exclude) parameters.Add("exclude","hashtags"); return await session.GetAsync(TwitterApi.Resolve("/1.1/trends/place.json"), parameters) .ContinueWith(c => c.MapToMany<TrendsForPlaceResponse>()); }
/// <summary> /// Returns the most recent direct messages sent by the authenticating user. /// </summary> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID</param> /// <param name="count">Specifies the number of direct messages to try and retrieve, up to a maximum of 200</param> /// <returns>(awaitable) IEnumerable of DirectMessages Sent by the session's authenticated user</returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent </remarks> public async static Task <TwitterResponseCollection <DirectMessage> > GetDirectMessagesSent(this IUserSession session, long sinceId = 0, long maxId = 0, int count = 20) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities: true, count: count, since_id: sinceId, max_id: maxId); return(await session.GetAsync(TwitterApi.Resolve("/1.1/direct_messages/sent.json"), parameters) .ContinueWith(c => c.MapToMany <DirectMessage>())); }
/// <summary> /// Returns a timeline of tweets authored by members of the specified list. Retweets are included by default. /// </summary> /// <param name="listId">The numerical id of the list.</param> /// <param name="slug">You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.</param> /// <param name="ownerId">The user ID of the user who owns the list being requested by a slug.</param> /// <param name="ownerScreenName">The screen name of the user who owns the list being requested by a slug.</param> /// <param name="sinceId">Returns results with an ID greater than (that is, more recent than) the specified ID.</param> /// <param name="count">Specifies the number of results to retrieve per "page."</param> /// <param name="maxId">Returns results with an ID less than (that is, older than) or equal to the specified ID.</param> /// <param name="includeRetweets">the list timeline will contain native retweets (if they exist) in addition to the standard stream of tweets.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/lists/statuses </remarks> public static async Task<TwitterResponseCollection<Tweet>> GetListTimeline(this ITwitterSession session, long listId, string slug, long ownerId = 0, string ownerScreenName = "", long sinceId = 0, int count = 20, long maxId = 0, bool includeRetweets = true) { var parameters = new TwitterParametersCollection { {"include_rts", includeRetweets.ToString()}, }; parameters.Create(list_id:listId, slug:slug, owner_id:ownerId, owner_screen_name:ownerScreenName, since_id:sinceId, max_id:maxId); return await session.GetAsync(TwitterApi.Resolve("/1.1/lists/statuses.json"), parameters) .ContinueWith(c => c.MapToMany<Tweet>()); }
/// <summary> /// Returns the locations that Twitter has trending topic information for, closest to a specified location. /// </summary> /// <param name="latitude">If provided with a long parameter the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair.</param> /// <param name="longitude">If provided with a lat parameter the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/trends/closest </remarks> public static async Task<TwitterResponseCollection<TrendsAvailableLocationsResponse>> GetTrendsByLocation( this ITwitterSession session, double latitude = 0.0, double longitude = 0.0) { var parameters = new TwitterParametersCollection { {"lat", latitude.ToString()}, {"long", longitude.ToString()}, }; return await session.GetAsync(TwitterApi.Resolve("/1.1/trends/closest.json"), parameters) .ContinueWith(c => c.MapToMany<TrendsAvailableLocationsResponse>()); }
/// <summary> /// Sends a direct message sent to a user. /// </summary> /// <param name="text">Text to send to user</param> /// <param name="screenName">Screen name of the recipient</param> /// <returns></returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/post/direct_messages/new </remarks> public async static Task<DirectMessage> SendDirectMessage(this IUserSession session, string screenName, string text) { var parameters = new TwitterParametersCollection(); parameters.Create(include_entities:true, screen_name:screenName, text:text.TrimAndTruncate(140)); if (parameters.EnsureAllArePresent(new [] {"screen_name", "text"}).IsFalse()) { return session.MapParameterError<DirectMessage>( "Either screen_name and text required"); } return await session.PostAsync(TwitterApi.Resolve("/1.1/direct_messages/new.json"), parameters) .ContinueWith(c => c.MapToSingle<DirectMessage>()); }
/// <summary> /// Report the specified user as a spam account to Twitter. Additionally performs the equivalent of POST blocks/create on behalf of the authenticated user. /// </summary> /// <param name="screenName">The ID or screen_name of the user you want to report as a spammer. Helpful for disambiguating when a valid screen name is also a user ID.</param> /// <param name="userId">The ID of the user you want to report as a spammer. Helpful for disambiguating when a valid user ID is also a valid screen name.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/users/report_spam </remarks> public async static Task<User> ReportUserForSpam(this IUserSession session, string screenName="", int userId=0) { var parameters = new TwitterParametersCollection(); parameters.Create(screen_name: screenName, user_id: userId); if (parameters.EnsureEitherOr("screen_name", "user_id").IsFalse()) { return session.MapParameterError<User>( "Either screen_name or user_id required"); } return await session.PostAsync(TwitterApi.Resolve("/1.1/users/report_spam.json"), parameters) .ContinueWith(c => c.MapToSingle<User>()); }
/// <summary> /// Returns a variety of information about the user specified by the required user_id or screen_name parameter. The author's most recent Tweet will be returned inline when possible. /// </summary> /// <param name="screenName">The screen name of the user for whom to return results for. Either a id or screen_name is required for this method.</param> /// <param name="userId">The ID of the user for whom to return results for. Either an id or screen_name is required for this method.</param> /// <returns></returns> public static async Task<User> GetUserProfile(this ITwitterSession session, string screenName="", long userId=0) { var parameters = new TwitterParametersCollection(); parameters.Create(screen_name:screenName,include_entities:true,user_id:userId); if (parameters.EnsureEitherOr("screen_name", "user_id").IsFalse()) { return session.MapParameterError<User>( "Either screen_name or user_id required"); } return await session.GetAsync(TwitterApi.Resolve("/1.1/users/show.json"), parameters) .ContinueWith(c => c.MapToSingle<User>()); }
/// <summary> /// Returns all lists the authenticating or specified user subscribes to, including their own. The user is specified using the user_id or screen_name parameters. If no user is given, the authenticating user is used. /// </summary> /// <param name="userId">The ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.</param> /// <param name="screenName">The screen name of the user for whom to return results for.</param> /// <param name="reverse">Set this to true if you would like owned lists to be returned first.</param> /// <returns>(awaitable) IEnumerable Lists the authenticated user or screen_name subscribes to</returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/lists/list </remarks> public static async Task<TwitterResponseCollection<TwitterList>> GetLists(this ITwitterSession session, long userId = 0, string screenName = "", bool reverse = false) { var parameters = new TwitterParametersCollection {{"reverse", reverse.ToString()}}; parameters.Create(screen_name: screenName, user_id: userId); if (parameters.EnsureEitherOr("screen_name", "user_id").IsFalse()) { return session.MapParameterError<TwitterResponseCollection<TwitterList>>( "Either screen_name or user_id required"); } return await session.GetAsync(TwitterApi.Resolve("/1.1/lists/list.json"), parameters) .ContinueWith(c => c.MapToMany<TwitterList>()); }
/// <summary> /// Returns a cursored collection of user IDs following a particular user(otherwise known as their "followers") /// </summary> /// <param name="cursor">default is first page (-1) otherwise provide starting point</param> /// <param name="userId">screen_name or user_id must be provided</param> /// <param name="screenName">screen_name or user_id must be provided</param> /// <param name="count">how many to return default 500</param> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/followers/ids </remarks> public static async Task<FriendsFollowersIDsCursored> GetFollowersIDs(this ITwitterSession session, string screenName = "", int userId = 0, int count = 500, long cursor = -1) { var parameters = new TwitterParametersCollection(); parameters.Create(count: count, cursor: cursor, screen_name: screenName, user_id: userId); if (parameters.EnsureEitherOr("screen_name", "user_id").IsFalse()) { return session.MapParameterError<FriendsFollowersIDsCursored>( "Either screen_name or user_id required"); } return await session.GetAsync(TwitterApi.Resolve("/1.1/followers/ids.json"), parameters) .ContinueWith(t => t.MapToSingle<FriendsFollowersIDsCursored>()); }
/// <summary> /// Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none. /// </summary> /// <param name="screenNames">list of screen_names to check</param> /// <param name="userIds">list of user_ids to check against</param> /// <returns></returns> /// <remarks> ref : https://dev.twitter.com/docs/api/1.1/get/friendships/lookup </remarks> public async static Task<TwitterResponseCollection<FriendshipLookupResponse>> GetFriendships(this IUserSession session, IEnumerable<string> screenNames = null, IEnumerable<long> userIds = null) { var parameters = new TwitterParametersCollection(); parameters.CreateCollection(screen_names: screenNames, user_ids:userIds); if (parameters.EnsureEitherOr("screen_name", "user_id").IsFalse()) { return session.MapParameterError<TwitterResponseCollection<FriendshipLookupResponse>>( "Either screen_names or user_ids required"); } var url = TwitterApi.Resolve("/1.1/friendships/lookup.json"); return await session.GetAsync(url, parameters) .ContinueWith(f => f.MapToMany<FriendshipLookupResponse>()); }
/// <summary> /// Given a latitude and a longitude, searches for up to 20 places that can be used as a place_id when updating a status. /// </summary> /// <param name="latitude">The latitude to search around.</param> /// <param name="longitude">The longitude to search around.</param> /// <param name="accuracy">A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If this is not passed in, then it is assumed to be 0m.</param> /// <param name="granularity">This is the minimal granularity of place types to return and must be one of: poi, neighborhood, city, admin or country.</param> /// <param name="maxResults">A hint as to the number of results to return.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode </remarks> public static async Task<ReverseGeoCodePlaces> GetPlaceIDFromGeocode(this IUserSession session, double latitude = 0.0, double longitude = 0.0, string accuracy = "10m", string granularity = "neighborhood", int maxResults=20) { var parameters = new TwitterParametersCollection { {"lat", latitude.ToString()}, {"long", longitude.ToString()}, {"accuracy", accuracy}, {"granularity", granularity}, {"max_results", maxResults.ToString()} }; return await session.GetAsync(TwitterApi.Resolve("/1.1/geo/reverse_geocode.json"), parameters) .ContinueWith(c => c.MapToSingle<ReverseGeoCodePlaces>()); }
/// <summary> /// dedicated API for running searches against the real-time index of recent Tweets. 6-9 days of historical data /// </summary> /// <param name="searchText">search query of 1,000 characters maximum, including operators. Queries may additionally be limited by complexity.</param> /// <param name="maxId"></param> /// <param name="sinceId"></param> /// <param name="untilDate">YYYY-MM-DD format</param> /// <param name="count">Tweets to return Default 20</param> /// <param name="searchResponseType">SearchResult.Mixed (default), SearchResult.Recent, SearchResult.Popular</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/search/tweets </remarks> public async static Task<SearchResponse> SearchFor(this ITwitterSession session, string searchText, SearchResultType searchResponseType, long maxId = 0, long sinceId = 0, string untilDate = "", int count = 20) { var parameters = new TwitterParametersCollection { {"q", searchText.TrimAndTruncate(1000).UrlEncode()}, {"result_type", SearchResultString(searchResponseType)}, }; parameters.Create(since_id:sinceId,max_id:maxId,count:count,include_entities:true); if (!string.IsNullOrWhiteSpace(untilDate)) { parameters.Add("until", untilDate); } return await session.GetAsync(TwitterApi.Resolve("/1.1/search/tweets.json"), parameters) .ContinueWith(c => c.MapToSingle<SearchResponse>()); }
public TwitterParametersCollection ChangeSearchParameters(IEnumerable<string> track = null, IEnumerable<string> follow = null, IEnumerable<string> locations = null, string filterlevel = "none", string language = "en") { var parameters = new TwitterParametersCollection(); parameters.Create(stall_warnings: false, delimited: false); if (track != null) parameters.CreateCommaDelimitedList("track", track); if (follow != null) parameters.CreateCommaDelimitedList("follow", follow); if (locations != null) parameters.CreateCommaDelimitedList("locations", locations); parameters.Add("filter_level", filterlevel); parameters.Add("language", language); return parameters; }
//https://dev.twitter.com/docs/streaming-apis/parameters public TwitterParametersCollection ChangeSearchParameters(StreamSearchRequest searchRequest) { var parameters = new TwitterParametersCollection(); parameters.Create(stall_warnings: false, delimited: false); if (searchRequest.Tracks.HasAny()) parameters.CreateCommaDelimitedList("track", searchRequest.Tracks); if (searchRequest.Follows.HasAny()) parameters.CreateCommaDelimitedList("follow", searchRequest.Follows); if (searchRequest.Locations.HasAny()) parameters.CreateCommaDelimitedList("locations", searchRequest.Locations); parameters.Add("filter_level", searchRequest.FilterLevel); parameters.Add("language", searchRequest.Language); return parameters; }
/// <summary> /// Sends a Tweet /// </summary> /// <param name="text">Text of tweet to send</param> /// <param name="latitude">Latitude of sender</param> /// <param name="longitude">Longotide of sender</param> /// <param name="placeId">A place in the world identified by a Twitter place ID. Place IDs can be retrieved from geo/reverse_geocode.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/statuses/update </remarks> public async static Task<Tweet> SendTweet(this IUserSession session, string text, double latitude = 0.0, double longitude = 0.0, string placeId="") { var parameters = new TwitterParametersCollection { { "status", text.TrimAndTruncate(1000)}, { "trim_user", true.ToString() }, }; parameters.Create(include_entities:true,place_id:placeId); if (Math.Abs(latitude) > 0.0 && Math.Abs(longitude) > 0.0) { parameters.Add("lat", latitude.ToString()); parameters.Add("long", longitude.ToString()); } return await session.PostAsync(TwitterApi.Resolve("/1.1/statuses/update.json"), parameters) .ContinueWith(c => c.MapToSingle<Tweet>()); }
/// <summary> /// Sends a Tweet in reply to another tweet /// </summary> /// <param name="tweet">Tweet replying to</param> /// <param name="text">Text of the reply</param> /// <param name="latitude">Latitude</param> /// <param name="longitude">Longitude</param> /// <param name="placeId">A place in the world identified by a Twitter place ID. Place IDs can be retrieved from geo/reverse_geocode.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/statuses/update </remarks> public async static Task<Tweet> ReplyToTweet(this IUserSession session, Tweet tweet, string text, double latitude=0.0, double longitude = 0.0, string placeId="") { var parameters = new TwitterParametersCollection { {"status", text }, {"in_reply_to_status_id", tweet.Id.ToString()} }; parameters.Create(place_id:placeId); if (Math.Abs(latitude) > 0.0 && Math.Abs(longitude) > 0.0) { parameters.Add("lat", latitude.ToString()); parameters.Add("long", longitude.ToString()); } return await session.PostAsync(TwitterApi.Resolve("/1.1/statuses/update.json"), parameters) .ContinueWith(c => c.MapToSingle<Tweet>()); }
/// <summary> /// Search for places that can be attached to a statuses/update. Given a latitude and a longitude pair, an IP address, or a name, this request will return a list of all the valid places that can be used as the place_id when updating a status /// </summary> /// <param name="query">Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name. Remember to URL encode the query.</param> /// <param name="latitude">The latitude to search around.</param> /// <param name="longitude">The longitude to search around.</param> /// <param name="accuracy">A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If this is not passed in, then it is assumed to be 0m.</param> /// <param name="containedWithin">This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.</param> /// <param name="granularity">This is the minimal granularity of place types to return and must be one of: poi, neighborhood, city, admin or country. If no granularity is provided for the request neighborhood is assumed.</param> /// <param name="maxResults">A hint as to the number of results to return.</param> /// <param name="ipAddress">An IP address. Used when attempting to fix geolocation based off of the user's IP address.</param> /// <returns></returns> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/geo/search </remarks> public static async Task<ReverseGeoCodePlaces> GetPlaceIDFromInfo(this IUserSession session, string query="", double latitude = 0.0, double longitude = 0.0, string accuracy = "10m", string containedWithin ="", string granularity = "neighborhood", int maxResults = 20, string ipAddress="") { var parameters = new TwitterParametersCollection { {"max_results", maxResults.ToString()} }; if (!string.IsNullOrWhiteSpace(query)) { parameters.Add("query", query); } if (!string.IsNullOrWhiteSpace(containedWithin)) { parameters.Add("contained_within", containedWithin); } if (!string.IsNullOrWhiteSpace(granularity)) { parameters.Add("granularity", granularity); } if (!string.IsNullOrWhiteSpace(ipAddress)) { parameters.Add("ip", ipAddress); } if (Math.Abs(latitude) > 0.0 && Math.Abs(longitude) > 0.0) { parameters.Add("lat", latitude.ToString()); parameters.Add("long", longitude.ToString()); if (!string.IsNullOrWhiteSpace(accuracy)) // nested because I think this only matters when lat/long is set { parameters.Add("accuracy", accuracy); } } return await session.GetAsync(TwitterApi.Resolve("/1.1/geo/search.json"), parameters) .ContinueWith(c => c.MapToSingle<ReverseGeoCodePlaces>()); }
/// <summary> /// Updates the authenticating user's settings. /// </summary> /// <param name="trendLocationWoeid">The Yahoo! Where On Earth ID to use as the user's default trend location.</param> /// <param name="sleepTimeEnabled">enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.</param> /// <param name="startSleepTime">The hour that sleep time should begin if it is enabled. (00)</param> /// <param name="endSleepTime">The hour that sleep time should end if it is enabled. (23) </param> /// <param name="timeZone">The timezone dates and times should be displayed in for the user. http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html </param> /// <param name="language">The language which Twitter should render in for this user https://dev.twitter.com/docs/api/1/get/help/languages </param> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/account/settings </remarks> public static async Task<AccountSettings> ChangeAccountSettings(this IUserSession session, string trendLocationWoeid = "1", bool sleepTimeEnabled = false, string startSleepTime = "", string endSleepTime = "", string timeZone = "", string language = "") { var parameters = new TwitterParametersCollection { {"sleep_time_enabled", sleepTimeEnabled.ToString()}, }; parameters.Create(include_entities: true); if (!string.IsNullOrWhiteSpace(trendLocationWoeid)) { parameters.Add("trend_location_woeid", trendLocationWoeid); } if (!string.IsNullOrWhiteSpace(startSleepTime)) { parameters.Add("start_sleep_time", startSleepTime); } if (!string.IsNullOrWhiteSpace(endSleepTime)) { parameters.Add("end_sleep_time", endSleepTime); } if (!string.IsNullOrWhiteSpace(timeZone)) { parameters.Add("time_zone", timeZone); } if (!string.IsNullOrWhiteSpace(language)) { parameters.Add("lang", language); } return await session.PostAsync(TwitterApi.Resolve("/1.1/account/settings.json"), parameters) .ContinueWith(c => c.MapToSingle<AccountSettings>()); }
/// <summary> /// Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user. /// </summary> /// <param name="cursor">default is first page (-1) otherwise provide starting point</param> /// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/friendships/incoming </remarks> public async static Task<FriendsFollowersIDsCursored> GetFriendshipRequestsIncoming(this IUserSession session, long cursor = -1) { var parameters = new TwitterParametersCollection(); parameters.Create(cursor:cursor); return await session.GetAsync(TwitterApi.Resolve("/1.1/friendships/incoming.json"), parameters) .ContinueWith(t => t.MapToSingle<FriendsFollowersIDsCursored>()); }
/// <summary> /// Deletes a sent direct message /// </summary> /// <param name="Id">ID of the direct message to delete</param> /// <returns>TwitterSuccess (true) if deletion worked</returns> /// <remarks>ref: https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy </remarks> public async static Task<TwitterSuccess> DeleteDirectMessage(this IUserSession session, long Id) { var parameters = new TwitterParametersCollection(); parameters.Create(id: Id); return await session.PostAsync(TwitterApi.Resolve("/1.1/direct_messages/destroy.json"), parameters) .ContinueWith(c => c.MapToTwitterSuccess()); }