本文整理汇总了C#中TwitterParametersCollection.EnsureAllArePresent方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterParametersCollection.EnsureAllArePresent方法的具体用法?C# TwitterParametersCollection.EnsureAllArePresent怎么用?C# TwitterParametersCollection.EnsureAllArePresent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterParametersCollection
的用法示例。
在下文中一共展示了TwitterParametersCollection.EnsureAllArePresent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendDirectMessage
/// <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>());
}
示例2: 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 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>());
}