private async void UploadWallPhoto() { var request = VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, 60479154); try { // upload var response = await request.ExecuteAsync(); Console.WriteLine("Photo: " + response.Json); // post photo var photoInfo = ((VKPhotoArray)response.ParsedModel).ObjectAtIndex <VKPhoto> (0); var photoAttachment = string.Format("photo{0}_{1}", photoInfo.owner_id, photoInfo.id); var post = VKApi.Wall.Post(new NSMutableDictionary <NSString, NSObject> { { VKApiConst.Attachment, (NSString)photoAttachment }, { VKApiConst.OwnerId, (NSNumber)OwnerId } }); var postResponse = await post.ExecuteAsync(); Console.WriteLine("Result: " + postResponse.Json); // open link var postId = ((NSDictionary)postResponse.Json) ["post_id"]; UIApplication.SharedApplication.OpenUrl(new NSUrl(string.Format("http://vk.com/wall{0}_{1}", OwnerId, postId))); } catch (VKException ex) { Console.WriteLine("Error: " + ex.Error); } }
private VKApi GetNewVkApi() { var api = new VKApi(); api.AddToken(_tokenRepo.GetToken()); return(api); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is VKPublishGameInfoToGroupNavigationParameters) { VKPublishGameInfoToGroupNavigationParameters = e.Parameter as VKPublishGameInfoToGroupNavigationParameters; } await SendLoading(); VKApi vkApi = new VKApi(); try { var response = await vkApi.Groups.Get(); var items = response.Response.Groups.Where(x => x.CanPost); if (items.Count() == 0) { VisualStateManager.GoToState(this, nameof(NoDataState), false); } else { Groups.ItemsSource = items; } } catch (VKApiException ex) { SendError(new VKError("Ошибка", ex.Message)); } SendLoaded(); }
public void SendToWall(string text, bool friendsOnly = false, SendToWallCallbackHandler callback = null) { cbSendToWall = callback; var req = new Hashtable(); req.Add("friends_only", friendsOnly ? "1" : "0"); req.Add("message", text); VKApi.Api(_reqSendToWall, req); }
private void HandleOAuthEvent(bool success, string error = "", string error_reason = "") { VKApi.CloseWebView(); Debug.LogWarning("OAuth authorization VK: " + success); if (cbAuthEvent != null) { cbAuthEvent(success, error, error_reason); } if (cbAuthEventShort != null) { cbAuthEventShort(success); } }
private async void UploadAlbumPhoto() { var request = VKApi.UploadAlbumPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), AlbumId, OwnerId); try { var response = await request.ExecuteAsync(); Console.WriteLine("Result: " + response.Json); var photoInfo = ((VKPhotoArray)response.ParsedModel).ObjectAtIndex <VKPhoto> (0); UIApplication.SharedApplication.OpenUrl(new NSUrl(string.Format("http://vk.com/photo{0}_{1}", OwnerId, photoInfo.id))); } catch (VKException ex) { Console.WriteLine("Error: " + ex.Error); } }
private async void UploadSinglePhotoToWall(object sender, EventArgs e) { var photo = GetPhoto(); var request = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.9f)), 0, OwnerId); try { var response = await request.ExecuteAsync(); RecycleBitmap(photo); var photoModel = ((VKPhotoArray)response.ParsedModel) [0]; MakePost("Photos from Xamarin.Android!", new VKAttachments(photoModel)); } catch (VKException ex) { ShowError(ex.Error); } }
async Task Publish() { await SendLoading(); VKApi vkApi = new VKApi(); try { //var wallUploadServerResponse = (await vkApi.Photos.GetWallUploadServer(Parameters.VKGroupID)).Response; //Debug.WriteLine($"GetUploadServer ->\n\turl: {wallUploadServerResponse.UploadUrl},\n\tuser_id: {wallUploadServerResponse.UserId},\n\talbum_id: {wallUploadServerResponse.AlbumID}"); //var uploadWallPhotoResponse = await vkApi.Photos.UploadWallPhoto( // await ApplicationData.Current.LocalFolder.GetFileAsync(Parameters.ScreenshotFileName), // wallUploadServerResponse.UploadUrl); //var savedPhoto = await vkApi.Photos.SaveWallPhoto( // wallUploadServerResponse.AlbumID, // /*wallUploadServerResponse.UserId*/0, // Parameters.VKGroupID, // //wallUploadServerResponse.UserId, // ///*Parameters.VKGroupID*/0, // uploadWallPhotoResponse.Photo, // uploadWallPhotoResponse.Server, // uploadWallPhotoResponse.Hash); var docsWallUploadServerResponse = (await vkApi.Docs.GetWallUploadServer(Parameters.VKGroupID)).Response; var docsUploadFileResponse = await vkApi.Docs.UploadWallFile( await ApplicationData.Current.LocalFolder.GetFileAsync(Parameters.PdfFileName), docsWallUploadServerResponse.UploadUrl); var doscSavedInfo = (await vkApi.Docs.SaveWallFile( docsUploadFileResponse.File)) .Response[0]; var wallPost = await vkApi.Wall.Post(-Parameters.VKGroupID, PublishingMessageTextBox.Text, //new VKAttachement(VKAttachementType.Photo, savedPhoto.OwnerID, savedPhoto.ID), new VKAttachement(VKAttachementType.Doc, doscSavedInfo.OwnerID, doscSavedInfo.ID)); VisualStateManager.GoToState(this, nameof(SuccessState), false); } catch (VKApiException ex) { SendError(new VKError("Ошибка", ex.Message)); } SendLoaded(); }
private async void UploadSinglePhoto(object sender, EventArgs e) { var photo = GetPhoto(); var request = VKApi.UploadAlbumPhotoRequest(new VKUploadImage(photo, VKImageParameters.PngImage()), AlbumId, OwnerId); try { var response = await request.ExecuteAsync(); RecycleBitmap(photo); var photoArray = (VKPhotoArray)response.ParsedModel; var uri = string.Format("https://vk.com/photo{0}_{1}", OwnerId, photoArray [0].id); var i = new Intent(Intent.ActionView, Uri.Parse(uri)); StartActivity(i); } catch (VKException ex) { ShowError(ex.Error); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { await SendLoading(); WebView.NavigationStarting += (s, args) => SendLoading(0); WebView.NavigationCompleted += (s, args) => SendLoaded(); VKApi vkApi = new VKApi(); vkApi.AuthorizationCompleted += (s, args) => { SendLoaded(); AuthorizationCompleted?.Invoke(this, args); }; vkApi.AuthorizationFailed += (s, args) => { SendLoaded(); SendError(args); }; vkApi.Authorize(WebView, VKUserPermissions.Groups | VKUserPermissions.Docs | VKUserPermissions.Wall | VKUserPermissions.Photos); }
public void GetFullFriendList(GetFriendsCallbackHandler callback = null, int offset = -1, int count = -1) { cbGetFriends = callback; friendsIsFull = true; var req = new Hashtable(); req.Add("order", "mobile"); if (offset >= 0) { req.Add("offset", offset.ToString()); } if (count >= 0) { req.Add("count", count.ToString()); } req.Add("fields", _reqGetFriends_FullList_Fields); VKApi.Api(_reqFriendsGet, req); }
private async void UploadMultiplePhotosToWall(object sender, EventArgs e) { var photo = GetPhoto(); var request1 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.9f)), 0, OwnerId); var request2 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.5f)), 0, OwnerId); var request3 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.1f)), 0, OwnerId); var request4 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.PngImage()), 0, OwnerId); var batch = new VKBatchRequest(request1, request2, request3, request4); var responses = await batch.ExecuteAsync(); try { RecycleBitmap(photo); var resp = responses.Select(r => ((VKPhotoArray)r.ParsedModel) [0]); var attachments = new VKAttachments(); attachments.AddRange(resp); MakePost("I just uploaded multiple files from the VK Xamarin.Android SDK!", attachments); } catch (VKException ex) { ShowError(ex.Error); } }
private async void UploadSeveralWallPhotos() { var batch = new VKBatchRequest(new [] { VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId), VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId), VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId), VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId) }); try { // upload var responses = await batch.ExecuteAsync(); Console.WriteLine("Photos: " + string.Concat(responses.Select(r => r.Json))); // create attachments var attachments = new List <string> (); foreach (var response in responses) { var photoInfo = ((VKPhotoArray)response.ParsedModel).ObjectAtIndex <VKPhoto> (0); var attachment = string.Format("photo{0}_{1}", photoInfo.owner_id, photoInfo.id); attachments.Add(attachment); } // post photos var post = VKApi.Wall.Post(new NSMutableDictionary <NSString, NSObject> { { VKApiConst.Attachments, (NSString)string.Join(",", attachments) }, { VKApiConst.OwnerId, (NSNumber)OwnerId } }); var postResponse = await post.ExecuteAsync(); Console.WriteLine("Result: " + postResponse.Json); // open link var postId = ((NSDictionary)postResponse.Json) ["post_id"]; UIApplication.SharedApplication.OpenUrl(new NSUrl(string.Format("http://vk.com/wall{0}_{1}", OwnerId, postId))); } catch (VKException ex) { Console.WriteLine("Error: " + ex.Error); } }
void Awake() { DontDestroyOnLoad(transform.gameObject); _vk = (VKApi)GetComponent <VKApi> (); }
static void Main(string[] args) { try { string login = "******"; string pass = "******"; l.Info("Программа запущена"); VKApi api = new VKApi(); if (!api.Authorize(login, pass, null, null)) { l.Error("failed to authorize! Wrong credentials."); } else { string input = Console.ReadLine(); int sw; Int32.TryParse(input, out sw); switch (sw) { case 1: Console.WriteLine("Starting count posts and likes"); Dictionary<long, int> users = new Dictionary<long, int>(); Dictionary<long, int> posts = new Dictionary<long, int>(); bool isFirstTime = true; int offset = 0; int postCount = 0; l.Info("Started"); do { WallResponse wall = api.GetWallPosts("100", Convert.ToString(offset)); if (isFirstTime) { postCount = wall.response.count; isFirstTime = false; } if (postCount < wall.response.count) { offset += wall.response.count - postCount; postCount = wall.response.count; } foreach (var w in wall.response.items) { if (!users.ContainsKey(w.from_id)) { users.Add(w.from_id, 0); } users[w.from_id] += w.likes.count; if (!posts.ContainsKey(w.from_id)) { posts.Add(w.from_id, 0); } posts[w.from_id]++; } offset += 100; } while (offset < 200000); Console.Write("Here we are"); var sortedUsers = from entry in users orderby entry.Value ascending select entry; var sortedPosts = from entry in posts orderby entry.Value ascending select entry; using (var wr = new StreamWriter("sortedUsers.txt")) { foreach (var entry in sortedUsers) { wr.Write("[{0} {1}]", entry.Key, entry.Value); } } using (var wr = new StreamWriter("sortedPosts.txt")) { foreach (var entry in sortedPosts) { wr.WriteLine("[*id{0} {1}]", entry.Key, entry.Value); } } break; case 2: Console.WriteLine("Starting count posts"); Console.Write("ss"); Console.Read(); break; default: break; //id = 115841733; //string group_id = "-88435"; //string question = "Забанить?"; //string answer = "[\"Yes pls\", \"No pls\"]"; //PollResponse poll = api.createPoll(group_id, question, answer); //string attachments = "poll" + poll.response.owner_id + "_" + poll.response.id; //string message = "Сыграем в игру?"; //api.PostMessage(group_id, message, attachments); } } } catch (WebException e) { l.Log(LogLevel.Error, "WebException", e); } }
public void DoLogIn(AuthEventHandlerShort callback = null) { cbAuthEventShort = callback; VKApi.Init(); }
public UploadHelper( VKApi api ) { _api = api; _client = new HttpClient(); }
public async Task <ActionResult> AllowAdvertisement(Guid id) { var advertisement = manager.GetAdvertisement(id); if (advertisement == null) { return(HttpNotFound()); } advertisement.Premoderated = true; manager.EditAdvertisement(advertisement); //need to change for production var urlToDetail = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port) + Url.Action("Details", advertisement.Category.ToString(), new { id = advertisement.Id }); //var urlToDetail = "https://ya.ru"; List <String> images = new List <String>(5); int i = 0; foreach (var image in advertisement.Images) { images.Add(Server.MapPath(Constants.ImagesFolder + image.Path)); if (++i > 4) { break; //max photo's count is 6 for VK Api (but last is a urlToDetail, so 5 photos) } } VKApi vkApi = new VKApi(); OKApi okApi = new OKApi(); string text = advertisement.Name; if (!String.IsNullOrEmpty(advertisement.Description)) { text += "\r\n" + advertisement.Description; } if (advertisement.Price.HasValue) { text += "\r\nЦена: " + advertisement.Price.ToString() + " руб."; } text += "\r\n\r\nКонтакты:\r\n" + advertisement.OwnerName; if (!String.IsNullOrEmpty(advertisement.Phone)) { text += "\r\n" + advertisement.Phone; } if (!String.IsNullOrEmpty(advertisement.VkId)) { text += "\r\n" + advertisement.VkId; } if (!String.IsNullOrEmpty(advertisement.OkId)) { text += "\r\n" + advertisement.OkId; } await vkApi.Post(text, images, urlToDetail); await okApi.Post(text, images, urlToDetail); return(RedirectToAction("Advertisements")); }
public UploadHelper(VKApi api) { _api = api; _client = new HttpClient(); }