public async Task <bool> Reorder(long audioId, long after, long before, long ownerId = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); parameters.Add("audio_id", audioId.ToString()); if (before != 0) { parameters.Add("before", before.ToString()); } if (after != 0) { parameters.Add("after", after.ToString()); } if (ownerId != 0) { parameters.Add("owner_id", ownerId.ToString()); } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "audio.reorder"), parameters).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(false); } if (response["response"] != null) { return(response["response"].Value <int>() == 1); } return(false); }
public async Task <bool> RegisterDevice(string token, string deviceModel = null, string systemVersion = null, bool noText = false, string subscribe = null) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parametres = new Dictionary <string, string>(); parametres.Add("token", token); if (!string.IsNullOrEmpty(deviceModel)) { parametres.Add("device_model", deviceModel); } if (!string.IsNullOrEmpty(systemVersion)) { parametres.Add("system_version", systemVersion); } if (noText) { parametres.Add("no_text", "1"); } _vkontakte.SignMethod(parametres); var response = await new VkRequest(new Uri(VkConst.MethodBase + "account.registerDevice"), parametres).Execute(); VkErrorProcessor.ProcessError(response); if (response["response"] != null) { return(response["response"].Value <int>() == 1); } return(false); }
/// <summary> /// Get albums of user or society. /// See also <see cref="http://vk.com/dev/audio.getAlbums"/> /// </summary> /// <param name="ownerId">Owner id. For society must be negative.</param> /// <param name="count">Count</param> /// <param name="offset">Offset</param> /// <returns></returns> public async Task <VkItemsResponse <VkAudioAlbum> > GetAlbums(long ownerId, int count = 0, int offset = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (ownerId != 0) { parameters.Add("owner_id", ownerId.ToString(CultureInfo.InvariantCulture)); } parameters.Add("count", count > 0 ? count.ToString(CultureInfo.InvariantCulture) : 100.ToString(CultureInfo.InvariantCulture) ); if (offset > 0) { parameters.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } _vkontakte.SignMethod(parameters); parameters["v"] = "5.68"; var response = await new VkRequest(new Uri(VkConst.MethodBase + "audio.getPlaylists"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { return(new VkItemsResponse <VkAudioAlbum>(response["response"]["items"].Select(VkAudioAlbum.FromJson).ToList(), (int)response["response"]["count"])); } return(VkItemsResponse <VkAudioAlbum> .Empty); }
public async Task <string> Get(string key) { var parameters = new Dictionary <string, string>(); parameters.Add("key", key); parameters.Add("access_token", _vkontakte.AccessToken.Token); var response = await new VkRequest(new Uri(VkConst.MethodBase + "storage.get"), parameters).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(null); } if (response["response"] != null) { return(response["response"].Value <string>()); } return(null); }
public async Task <bool?> GetBroadcast() { //TODO метода audio.getBroadcast больше нет if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var response = await new VkRequest(new Uri(VkConst.MethodBase + "audio.getBroadcast"), null).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(null); } if (response["response"] != null) { return(response["response"].Value <int>() == 1); } return(null); }
public async Task <VkItemsResponse <VkGroup> > Search(string query, VkGroupSearchType sort = VkGroupSearchType.ByUsers, int count = 0, int offset = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(query)) { parameters.Add("q", query); } parameters.Add("sort", ((int)sort).ToString()); if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "groups.search"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { return(new VkItemsResponse <VkGroup>((from g in response["response"]["items"] where g.HasValues select VkGroup.FromJson(g)).ToList(), response["response"]["count"].Value <int>())); } return(VkItemsResponse <VkGroup> .Empty); }
public async Task <VkWallResult> Get(string ownerId, string filter, int count = 0, int offset = 0) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(ownerId)) { dictionary.Add("owner_id", ownerId); } if (!string.IsNullOrEmpty(filter)) { dictionary.Add("filter", filter); } if (count > 0) { dictionary.Add("count", count.ToString()); } if (offset > 0) { dictionary.Add("offset", offset.ToString()); } dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token); JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/wall.get"), dictionary, "GET").Execute(); VkErrorProcessor.ProcessError(jObject); VkWallResult result; if (jObject["response"] != null) { VkWallResult vkWallResult = new VkWallResult(); vkWallResult.Count = jObject["response"].First.Value <int>(); vkWallResult.Posts = Enumerable.Select <JToken, VkWallEntry>(Enumerable.Where <JToken>(jObject["response"], (JToken p) => p.HasValues), (JToken p) => VkWallEntry.FromJson(p)); result = vkWallResult; } else { result = null; } return(result); }
public async Task <IEnumerable <VkCity> > Get(IEnumerable <string> cids) { var dictionary = new Dictionary <string, string>(); if (cids != null) { dictionary.Add("cids", string.Join(",", cids)); } JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/places.getCityById"), dictionary, "GET").Execute(); VkErrorProcessor.ProcessError(jObject); IEnumerable <VkCity> result; if (jObject["response"].HasValues) { result = Enumerable.Select <JToken, VkCity>(jObject["response"], (JToken u) => VkCity.FromJson(u)); } else { result = null; } return(result); }
public async Task <IEnumerable <VkPhotoAlbum> > Get(string uid, IList <string> aids = null, int needSystem = 0, int needCovers = 0, int needSizes = 0) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (aids != null) { dictionary.Add("aids", string.Join(",", aids)); } if (!string.IsNullOrEmpty(uid)) { dictionary.Add("uid", uid); } dictionary.Add("need_system", needSystem.ToString()); dictionary.Add("need_covers", needCovers.ToString()); dictionary.Add("photo_sizes", needSizes.ToString()); JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/photos.getAlbums"), dictionary, "GET").Execute(); IEnumerable <VkPhotoAlbum> result; if (VkErrorProcessor.ProcessError(jObject)) { result = null; } else { if (jObject["response"].HasValues) { //result = Enumerable.Select<JToken, VkPhotoAlbum>(Enumerable.Skip<JToken>(jObject["response"], 1), (JToken a) => VkPhotoAlbum.FromJson(a)); result = Enumerable.Select <JToken, VkPhotoAlbum>(Enumerable.Where <JToken>(jObject["response"], (JToken v) => v.HasValues), (JToken v) => VkPhotoAlbum.FromJson(v)); } else { result = null; } } return(result); }
public async Task <VkItemsResponse <VkProfile> > Get(IEnumerable <string> userIds, string fields = null, string nameCase = null) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (userIds != null) { parameters.Add("user_ids", string.Join(",", userIds)); } if (!string.IsNullOrWhiteSpace(fields)) { parameters.Add("fields", fields); } if (!string.IsNullOrWhiteSpace(nameCase)) { parameters.Add("name_case", nameCase); } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "users.get"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response") != null) { return(new VkItemsResponse <VkProfile>((from u in response["response"] select VkProfile.FromJson(u)).ToList())); } return(VkItemsResponse <VkProfile> .Empty); }
public async Task <VkPhoto> SaveWallPhoto(string server, string photo, string hash, long userId = 0, long groupId = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); parameters.Add("server", server); parameters.Add("photo", photo); parameters.Add("hash", hash); if (userId != 0) { parameters.Add("user_id", userId.ToString()); } if (groupId != 0) { parameters.Add("group_id", groupId.ToString()); } parameters.Add("access_token", _vkontakte.AccessToken.Token); var response = await new VkRequest(new Uri(VkConst.MethodBase + "photos.saveWallPhoto"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response["response"] != null) { return(VkPhoto.FromJson(response["response"].First)); } return(null); }
public async Task <IEnumerable <VkVideo> > Get(IList <string> videos = null, string uid = null, string gid = null, string aid = null, int previewWidth = 0, int count = 0, int offset = 0) { if (count > 200) { throw new ArgumentException("Maximum count is 200."); } Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (videos != null) { dictionary.Add("videos", string.Join(",", videos)); } if (!string.IsNullOrEmpty(uid)) { dictionary.Add("uid", uid); } if (!string.IsNullOrEmpty(gid)) { dictionary.Add("gid", gid); } if (!string.IsNullOrEmpty(aid)) { dictionary.Add("aid", aid); } if (previewWidth > 0) { dictionary.Add("width", previewWidth.ToString(CultureInfo.InvariantCulture)); } if (count > 0) { dictionary.Add("count", count.ToString(CultureInfo.InvariantCulture)); } else { dictionary.Add("count", 200.ToString(CultureInfo.InvariantCulture)); } if (offset > 0) { dictionary.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token); JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/video.get"), dictionary, "GET").Execute(); IEnumerable <VkVideo> result; if (VkErrorProcessor.ProcessError(jObject)) { result = null; } else { if (jObject["response"].HasValues) { result = Enumerable.Select <JToken, VkVideo>(Enumerable.Where <JToken>(jObject["response"], (JToken v) => v.HasValues), (JToken v) => VkVideo.FromJson(v)); } else { result = null; } } return(result); }
public async Task <IEnumerable <VkVideo> > Search(string query, int count = 0, int offset = 0, bool hdOnly = false, VkAudioSortType sort = VkAudioSortType.DateAdded, bool adult = false) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } if (count > 200) { throw new ArgumentException("Maximum count is 200."); } if (query == null) { throw new ArgumentException("Query must not be null."); } var parameters = new Dictionary <string, string>(); parameters.Add("q", query); if (hdOnly) { parameters.Add("hd", "1"); } parameters.Add("sort", ((int)sort).ToString(CultureInfo.InvariantCulture)); if (adult) { parameters.Add("adult", "1"); } if (count > 0) { parameters.Add("count", count.ToString(CultureInfo.InvariantCulture)); } else { parameters.Add("count", MAX_VIDEO_COUNT.ToString(CultureInfo.InvariantCulture)); } if (offset > 0) { parameters.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } parameters.Add("access_token", _vkontakte.AccessToken.Token); var response = await new VkRequest(new Uri(VkConst.MethodBase + "video.search"), parameters).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(null); } if (response["response"].HasValues) { return(from v in response["response"] select VkVideo.FromJson(v)); } return(null); }
public async Task <IEnumerable <VkVideo> > Get(IList <string> videos, string uid = null, string gid = null, string aid = null, int previewWidth = 0, int count = 0, int offset = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } if (count > 200) { throw new ArgumentException("Maximum count is 200."); } var parameters = new Dictionary <string, string>(); if (videos != null) { parameters.Add("videos", string.Join(",", videos)); } if (!string.IsNullOrEmpty(uid)) { parameters.Add("uid", uid); } if (!string.IsNullOrEmpty(gid)) { parameters.Add("gid", gid); } if (!string.IsNullOrEmpty(aid)) { parameters.Add("aid", aid); } if (previewWidth > 0) { parameters.Add("width", previewWidth.ToString(CultureInfo.InvariantCulture)); } if (count > 0) { parameters.Add("count", count.ToString(CultureInfo.InvariantCulture)); } else { parameters.Add("count", MAX_VIDEO_COUNT.ToString(CultureInfo.InvariantCulture)); } if (offset > 0) { parameters.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } parameters.Add("access_token", _vkontakte.AccessToken.Token); var response = await new VkRequest(new Uri(VkConst.MethodBase + "video.get"), parameters).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(null); } if (response["response"].HasValues) { return(from v in response["response"] where v.HasValues select VkVideo.FromJson(v)); } return(null); }
/// <summary> /// Search audios. /// See also <see cref="http://vk.com/dev/audio.search"/> /// </summary> /// <param name="query">Query</param> /// <param name="count">Count</param> /// <param name="offset">Offset</param> /// <param name="sort">Sort</param> /// <param name="withLyricsOnly">If true will show only audios with lyrics</param> /// <param name="autoFix">If true will fix incorrect queries</param> /// <param name="artistOnly">If true will search only by artist</param> /// <param name="ownOnly">If true will search only in audios of current user</param> /// <returns></returns> public async Task <VkItemsResponse <VkAudio> > Search(string query, int count = 0, int offset = 0, VkAudioSortType sort = VkAudioSortType.DateAdded, bool withLyricsOnly = false, bool autoFix = true, bool artistOnly = false, bool ownOnly = false) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } if (count > MAX_AUDIO_COUNT) { throw new ArgumentException("Maximum count is " + MAX_AUDIO_COUNT + "."); } if (query == null) { throw new ArgumentException("Query must not be null."); } var parameters = new Dictionary <string, string>(); parameters.Add("q", query); if (autoFix) { parameters.Add("auto_complete", "1"); } parameters.Add("sort", ((int)sort).ToString(CultureInfo.InvariantCulture)); if (withLyricsOnly) { parameters.Add("lyrics", "1"); } if (artistOnly) { parameters.Add("performer_only", "1"); } if (ownOnly) { parameters.Add("search_own", "1"); } if (count > 0) { parameters.Add("count", count.ToString(CultureInfo.InvariantCulture)); } else { parameters.Add("count", MAX_AUDIO_COUNT.ToString(CultureInfo.InvariantCulture)); } if (offset > 0) { parameters.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "audio.search"), parameters).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(null); } if (response.SelectToken("response.items") != null) { return(new VkItemsResponse <VkAudio>((from a in response["response"]["items"] where a.HasValues && !string.IsNullOrEmpty(a["url"].Value <string>()) select VkAudio.FromJson(a)).ToList(), response["response"]["count"].Value <int>())); } return(VkItemsResponse <VkAudio> .Empty); }
public async Task <VkItemsResponse <VkWallEntry> > Get(long ownerId, string filter, int count = 0, int offset = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (ownerId != 0) { parameters.Add("owner_id", ownerId.ToString()); } if (!string.IsNullOrEmpty(filter)) { parameters.Add("filter", filter); } if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } parameters.Add("extended", "1"); _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "wall.get"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { var result = new VkItemsResponse <VkWallEntry>(); result.Items = (from p in response["response"]["items"] where p.HasValues select VkWallEntry.FromJson(p)).ToList(); result.TotalCount = response["response"]["count"].Value <int>(); if (response["response"]["profiles"] != null) { var users = (from n in response["response"]["profiles"] select VkProfile.FromJson(n)).ToList(); foreach (var entry in result.Items) { entry.Author = users.FirstOrDefault(u => u.Id == entry.SourceId); } } if (response["response"]["groups"] != null) { var groups = (from n in response["response"]["groups"] select VkGroup.FromJson(n)).ToList(); foreach (var entry in result.Items.Where(e => e.Author == null)) { entry.Author = groups.FirstOrDefault(g => g.Id == Math.Abs(entry.SourceId)); } } return(result); } return(null); }
public async Task <VkNewsResponse> Get(string sourceIds = null, string filters = null, int count = 0, string startFrom = null) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(sourceIds)) { parameters.Add("source_ids", sourceIds); } if (!string.IsNullOrEmpty(filters)) { parameters.Add("filters", filters); } if (count > 0) { parameters.Add("count", count.ToString()); } if (!string.IsNullOrEmpty(startFrom)) { parameters.Add("start_from", startFrom); } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "newsfeed.get"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { var result = new VkNewsResponse((from n in response["response"]["items"] select VkNewsEntry.FromJson(n)).ToList()); if (response["response"]["profiles"] != null) { var users = (from n in response["response"]["profiles"] select VkProfile.FromJson(n)).ToList(); foreach (var entry in result.Items) { entry.Author = users.FirstOrDefault(u => u.Id == entry.SourceId); } } if (response["response"]["groups"] != null) { var groups = (from n in response["response"]["groups"] select VkGroup.FromJson(n)).ToList(); foreach (var entry in result.Items.Where(e => e.Author == null)) { entry.Author = groups.FirstOrDefault(g => g.Id == Math.Abs(entry.SourceId)); } } if (response["response"]["next_from"] != null) { result.NextFrom = response["response"]["next_from"].Value <string>(); } return(result); } return(null); }
public async Task <VkItemsResponse <VkProfile> > Get(long userId, string fields, string nameCase, int count, int offset, FriendsOrder order = FriendsOrder.ByName) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } var parameters = new Dictionary <string, string>(); if (userId > 0) { parameters.Add("user_id", userId.ToString()); } if (!string.IsNullOrWhiteSpace(fields)) { parameters.Add("fields", fields); } if (!string.IsNullOrWhiteSpace(nameCase)) { parameters.Add("name_case", nameCase); } if (count > 0) { parameters.Add("count", count.ToString()); } if (offset > 0) { parameters.Add("offset", offset.ToString()); } switch (order) { case FriendsOrder.ByName: parameters.Add("order", "name"); break; case FriendsOrder.ByRating: parameters.Add("order", "hints"); break; case FriendsOrder.Random: parameters.Add("order", "random"); break; } _vkontakte.SignMethod(parameters); var response = await new VkRequest(new Uri(VkConst.MethodBase + "friends.get"), parameters).Execute(); VkErrorProcessor.ProcessError(response); if (response.SelectToken("response.items") != null) { return(new VkItemsResponse <VkProfile>(response["response"]["items"].Select(VkProfile.FromJson).ToList(), (int)response["response"]["count"])); } return(VkItemsResponse <VkProfile> .Empty); }