本文整理汇总了C#中AccessToken.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# AccessToken.ContainsKey方法的具体用法?C# AccessToken.ContainsKey怎么用?C# AccessToken.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AccessToken
的用法示例。
在下文中一共展示了AccessToken.ContainsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserInfo
/// <summary>
/// Gets the user details.
/// </summary>
/// <param name="accessToken">May contain an access token, which will have to be used in obtaining information about the user.</param>
/// <exception cref="ApiException"/>
public override UserInfo GetUserInfo(AccessToken accessToken = null)
{
// help: http://vk.com/dev/users.get
accessToken = base.GetSpecifiedTokenOrCurrent(accessToken);
// query parameters
var parameters = new NameValueCollection
{
{ "user_ids", accessToken["user_id"].ToString() },
{ "fields", "sex,bdate,city,country,photo_max_orig,domain,contacts,site" }
};
// execute the request
var result = OAuthUtility.Get
(
"https://api.vk.com/method/users.get",
parameters: parameters,
accessToken: accessToken
);
if (result.ContainsKey("error"))
{
throw new ApiException(result, result["error"]["error_msg"].ToString());
}
// field mapping
var map = new ApiDataMapping();
map.Add("uid", "UserId", typeof(string));
map.Add("first_name", "FirstName");
map.Add("last_name", "LastName");
map.Add("domain", "UserName");
map.Add("photo_max_orig", "Userpic");
map.Add("mobile_phone", "Phone");
map.Add("bdate", "Birthday", typeof(DateTime), @"dd\.MM\.yyyy");
map.Add
(
"site", "Url",
delegate(UniValue value)
{
if (value.HasValue || String.IsNullOrEmpty(value.ToString())) { return null; }
return value.ToString().Split(' ').First();
}
);
map.Add
(
"sex", "Sex",
delegate(UniValue value)
{
if (Convert.ToInt32(value) == 2)
{
return Sex.Male;
}
else if (Convert.ToInt32(value) == 1)
{
return Sex.Female;
}
return Sex.None;
}
);
// email, thanks to Aleksander (KamAz) Kryatov (http://vk.com/acid_rock) for idea
if (accessToken.ContainsKey("email"))
{
result["response"].First().Add("at_email", accessToken["email"]);
map.Add("at_email", "Email", typeof(string));
}
// --
// parse the server response and returns the UserInfo instance
return new UserInfo(result["response"].First(), map);
}