本文整理汇总了C#中TwitterParametersCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterParametersCollection.Add方法的具体用法?C# TwitterParametersCollection.Add怎么用?C# TwitterParametersCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterParametersCollection
的用法示例。
在下文中一共展示了TwitterParametersCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeSearchParameters
//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;
}
示例2: SendTweet
/// <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>());
}
示例3: ReplyToTweet
/// <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>());
}
示例4: GetPlaceIDFromInfo
/// <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>());
}
示例5: SearchFor
/// <summary>
/// Geotagged dedicated API for running searches against the real-time index of recent Tweets. 6-9 days
/// </summary>
/// <param name="searchText">search query of 1,000 characters maximum, including operators. Queries may additionally be limited by complexity.</param>
/// <param name="latitude">Returns tweets by users located within a given radius of the given latitude/longitude.</param>
/// <param name="longitude">Returns tweets by users located within a given radius of the given latitude/longitude.</param>
/// <param name="distance">Returns tweets by users located within a given radius of the given latitude/longitude.</param>
/// <param name="distanceUnits">km (default) or mi</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, double latitude, double longitude, double distance, string distanceUnits="km", 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);
}
parameters.Add("geocode",String.Format("{0},{1},{2}{3}",latitude,longitude,distance,distanceUnits));
return await session.GetAsync(TwitterApi.Resolve("/1.1/search/tweets.json"), parameters)
.ContinueWith(c => c.MapToSingle<SearchResponse>());
}
示例6: GetTrendsForPlace
/// <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>());
}
示例7: ChangeAccountSettings
/// <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>());
}
示例8: GetFriendship
/// <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>());
}
示例9: CreateList
/// <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">The name for the list.</param>
/// <param name="mode">Whether your list is public or private. Values can be public or private. If no mode is specified the list will be public.</param>
/// <param name="description">The description to give the list.</param>
/// <returns></returns>
/// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/lists/update </remarks>
public static async Task<TwitterList> CreateList(this IUserSession session, string name, string mode, string description = "", long ownerId = 0,
string ownerScreenName = "")
{
var parameters = new TwitterParametersCollection
{
{"name", name},
{"mode", mode},
};
if (!string.IsNullOrWhiteSpace(description))
{
parameters.Add("description", description);
}
return await session.PostAsync(TwitterApi.Resolve("/1.1/lists/create.json"), parameters)
.ContinueWith(c => c.MapToSingle<TwitterList>());
}
示例10: ChangeList
/// <summary>
/// Updates the specified list. The authenticated user must own the list to be able to update it.
/// </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="name">The name for the list.</param>
/// <param name="mode">Whether your list is public or private. Values can be public or private. If no mode is specified the list will be public.</param>
/// <param name="description">The description to give the list.</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/post/lists/update </remarks>
public static async Task<TwitterSuccess> ChangeList(this IUserSession session, long listId,
string slug, string name = "", string mode = "", string description = "", long ownerId = 0,
string ownerScreenName = "")
{
var parameters = new TwitterParametersCollection();
parameters.Create(name:name, list_id: listId, slug: slug, owner_id: ownerId, owner_screen_name: ownerScreenName);
if (!string.IsNullOrWhiteSpace(mode))
{
parameters.Add("mode", mode);
}
if (!string.IsNullOrWhiteSpace(description))
{
parameters.Add("description", description);
}
return await session.PostAsync(TwitterApi.Resolve("/1.1/lists/update.json"), parameters)
.ContinueWith(c => c.MapToTwitterSuccess());
}
示例11: ChangeProfileBanner
/// <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());
}
示例12: ChangeAccountColours
/// <summary>
/// Sets one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com. Each parameter's value must be a valid hexidecimal value, and may be either three or six characters (ex: #fff or #ffffff).
/// </summary>
/// <param name="profileBackgroundColor">Example Values: 3D3D3D</param>
/// <param name="profileLinkColor">Example Values: 3D3D3D</param>
/// <param name="profileSidebarBorderColor">Example Values: 3D3D3D</param>
/// <param name="profileSidebarFillColor">Example Values: 3D3D3D</param>
/// <param name="profileTextColor">Example Values: 3D3D3D</param>
/// <remarks> ref: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors </remarks>
public static async Task<User> ChangeAccountColours(this IUserSession session,
string profileBackgroundColor = "", string profileLinkColor = "", string profileSidebarBorderColor = "",
string profileSidebarFillColor = "", string profileTextColor = "")
{
var parameters = new TwitterParametersCollection();
parameters.Create(include_entities: true, skip_status: true);
if (!string.IsNullOrWhiteSpace(profileBackgroundColor))
{
parameters.Add("profile_background_color", profileBackgroundColor);
}
if (!string.IsNullOrWhiteSpace(profileLinkColor))
{
parameters.Add("profile_link_color", profileLinkColor);
}
if (!string.IsNullOrWhiteSpace(profileSidebarBorderColor))
{
parameters.Add("profile_sidebar_border_color", profileSidebarBorderColor);
}
if (!string.IsNullOrWhiteSpace(profileSidebarFillColor))
{
parameters.Add("profile_sidebar_fill_color", profileSidebarFillColor);
}
if (!string.IsNullOrWhiteSpace(profileTextColor))
{
parameters.Add("profile_text_color", profileTextColor);
}
return await session.PostAsync(TwitterApi.Resolve("/1.1/account/update_profile_colors.json"), parameters)
.ContinueWith(c => c.MapToSingle<User>());
}
示例13: ChangeAccountProfile
/// <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>());
}
示例14: GetPlaceSimilarName
/// <summary>
/// Locates places near the given coordinates which are similar in name.
/// NOTE: The token contained in the response is the token needed to be able to create a new place.
/// </summary>
/// <param name="name">The name a place is known as.</param>
/// <param name="latitude">The latitude to search around</param>
/// <param name="longitude">The longitude to search around</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>
/// <returns></returns>
/// <remarks> ref: https://dev.twitter.com/docs/api/1.1/get/geo/similar_places </remarks>
public static async Task<ReverseGeoCodePlaces> GetPlaceSimilarName(this IUserSession session,
string name = "", double latitude = 0.0,
double longitude = 0.0, string containedWithin = "")
{
var parameters = new TwitterParametersCollection
{
{"lat", latitude.ToString()},
{"long", longitude.ToString()},
{"name",name}
};
if (!string.IsNullOrWhiteSpace(containedWithin))
{
parameters.Add("contained_within", containedWithin);
}
return await session.GetAsync(TwitterApi.Resolve("/1.1/geo/similar_places.json"), parameters)
.ContinueWith(c => c.MapToSingle<ReverseGeoCodePlaces>());
}
示例15: ReplyToTweetWithImage
/// <summary>
/// Sends a Tweet in reply to another tweet
/// </summary>
/// <param name="tweet">Text to send</param>
/// <param name="text">Text of tweet to send</param>
/// <param name="fileName">Name of the file, including extension</param>
/// <param name="imageDataStream">Stream containing the image</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_with_media </remarks>
public async static Task<Tweet> ReplyToTweetWithImage(this IUserSession session, Tweet tweet, string text, string fileName, Stream imageDataStream, 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.PostFileAsync(TwitterApi.Upload("/1.1/statuses/update_with_media.json"), parameters, fileName, "media[]", srImage: imageDataStream)
.ContinueWith(c => c.MapToSingle<Tweet>());
}