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);
            }
        }
示例#2
0
            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);
                }
            }
示例#3
0
            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);
            }
        }