.NET 4.x Не получается передать параметры в метод - C#
Формулировка задачи:
Доброго времени суток. Использую библиотеку VkNet. Пытаюсь получить пост используя wall.getById()
Не могу понять где я ошибаюсь
Листинг программы
- long groupId = -11111111;
- long postIds = 333;
- ICollection<KeyValuePair<long, long>> posts = new Dictionary<long, long>();
- posts.Add(new KeyValuePair<long, long>(groupId, postIds));
- var copyPost = vk.Wall.GetById(posts); <-- В этом месте вываливается ошибка.
Листинг программы
- An unhandled exception of type 'System.NullReferenceException' occurred in VkNet.dll
- Additional information: Ссылка на объект не указывает на экземпляр объекта.
Решение задачи: «.NET 4.x Не получается передать параметры в метод»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using VkNet;
- using VkNet.Enums;
- using VkNet.Enums.Filters;
- using VkNet.Model;
- using VkNet.Model.Attachments;
- namespace wallCopyPostVk
- {
- public partial class Form1 : Form
- {
- public static VkApi vk = new VkApi();
- long groupId = -****;//Одкуда берем посты
- long myGroups = -***;//Куда копируем посты
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- int appId = 4857486; // указываем id приложения
- string email = "*******"; // email для авторизации
- string password = "q*****"; // пароль
- Settings settings = Settings.All; // уровень доступа к данным
- vk.Authorize(appId, email, password, settings);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int totalCount;
- ReadOnlyCollection<Post> listPost = vk.Wall.Get(groupId, out totalCount, 50, 0, WallFilter.All);
- listView1.View = View.Details;
- listView1.GridLines = true;
- listView1.FullRowSelect = true;
- listView1.CheckBoxes = true;
- listView1.Columns.Add("Text");
- listView1.Columns.Add("postId");
- listView1.Columns.Add("attachment");
- listView1.Items.Clear();
- for (int i = 0; i < listPost.Count(); i++ )
- {
- listView1.Items.Add(listPost[i].Text);
- listView1.Items[i].SubItems.Add(listPost[i].Id.ToString());
- //listView1.Items[i].SubItems.Add(listPost[i].Attachment.ToString());
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- DateTime timesAdd = DateTime.Now;
- timesAdd = timesAdd.AddMinutes(30);
- int totalCount;
- ReadOnlyCollection<Post> listPost = vk.Wall.Get(groupId, out totalCount, 50, 0, WallFilter.All);
- var attachments = new List<MediaAttachment>
- {
- };
- foreach (var test in listPost)
- {
- MessageBox.Show(test.Attachments.ToList().ToString());
- }
- for (int i = 0; i < listView1.Items.Count; i++)
- {
- if (listView1.Items[i].Checked == true)
- {
- string[] post = { groupId + "_" + listView1.Items[i].SubItems[1].Text };
- //long postIds = Convert.ToInt64(listView1.Items[i].SubItems[1].Text);
- //IEnumerable<string> posts = new ;
- //vk.Wall.GetById(posts);
- var result = vk.Wall.Post(myGroups, false, true, listView1.Items[i].SubItems[0].Text,null, null, null, false, timesAdd);
- // foreach (var poste in postCopy)
- // {
- // MessageBox.Show(poste.Text);
- // }
- }
- }
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д