K
Klem56March 5, 2022, 11:34 a.m.

Vk api на java. Как сделать кнопки

Java, VK, API

Вот код:

public class Bot {
public static void main(String[] args) throws ClientException, ApiException, InterruptedException {
TransportClient transportClient = new HttpTransportClient();
VkApiClient vk = new VkApiClient(transportClient);
Random random = new Random();
Keyboard keyboard = new Keyboard();
List > allKey = new ArrayList<>();
List line1 = new ArrayList<>();
line1.add(new KeyboardButton()).setAction(new KeyboardButtonAction().setLabel("Привет").setType(KeyboardButtonActionType.TEXT).setColor(KeyboardButtonColor.POSITIVE));
line1.add(new KeyboardButton()).setAction(new KeyboardButtonAction().setLabel("Кто я?").setType(KeyboardButtonActionType.TEXT).setColor(KeyboardButtonColor.POSITIVE));
keyboard.setButtons(allKey);
GroupActor actor = new GroupActor(211045078, "Key");
Integer ts = vk.messages().getLongPollServer(actor).execute().getTs();
while(true){
MessagesGetLongPollHistoryQuery historyQuery = vk.messages().getLongPollHistory(actor).ts(ts);
List messages = historyQuery.execute().getMessages().getItems();
if(!messages.isEmpty()){
messages.forEach(message -> {
System.out.println(message.toString());
try {
if (message.getText().equals("Привет")){
vk.messages().send(actor).message("Привет").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
}
else if (message.getText().equals("Кто я?")) {
vk.messages().send(actor).message("Ты хороший человек.").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
}
else if (message.getText().equals("Кнопки")){
vk.messages().send(actor).message("А вот и они").userId(message.getFromId()).randomId(random.nextInt(10000)).keyboard(keyboard).execute();
}
else {
vk.messages().send(actor).message("Я тебя не понял").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
}
}catch (ApiException | ClientException e) {e.printStackTrace();}
});
}
ts = vk.messages().getLongPollServer(actor).execute().getTs();
Thread.sleep(500);
}
}
}

И на строке---
line1.add(new KeyboardButton()).setAction(new KeyboardButtonAction().setLabel("Привет").setType(KeyboardButtonActionType.TEXT).setColor(KeyboardButtonColor.POSITIVE));

Выдаёт ошибку 'setType(com.vk.api.sdk.objects.messages.TemplateActionTypeNames)' in 'com.vk.api.sdk.objects.messages.KeyboardButtonAction' cannot be applied to '(com.vk.api.sdk.objects.messages.KeyboardButtonActionType)'
Как это решить? Для java докуменация просто идиотия:|

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

1
АМ
  • March 24, 2022, 2:12 a.m.

Првиет
line1.add(new KeyboardButton().setAction(new KeyboardButtonAction().setLabel("Текст кнопки").setType(TemplateActionTypeNames.TEXT)).setColor(KeyboardButtonColor.POSITIVE));

А вообще там градл уже другой

plugins {
id 'java'
id 'application'
}
apply plugin: 'java'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
mavenCentral()
}

mainClassName = 'class.name'

dependencies {
implementation 'com.vk.api:sdk:1.0.7'
}

    Comments

    Only authorized users can post comments.
    Please, Log in or Sign up
    AD

    C ++ - Test 004. Pointers, Arrays and Loops

    • Result:50points,
    • Rating points-4
    m

    C ++ - Test 004. Pointers, Arrays and Loops

    • Result:80points,
    • Rating points4
    m

    C ++ - Test 004. Pointers, Arrays and Loops

    • Result:20points,
    • Rating points-10
    Last comments
    i
    innorwallNov. 15, 2024, 2:30 p.m.
    Qt/C++ - Lesson 065. The correspondence of HTTP errors to server response errors in QNetworkAccessManager s Midsummer Classic in Kansas City priligy online pharmacy
    i
    innorwallNov. 15, 2024, 1:44 p.m.
    Qt/C++ - Lesson 039. How to paint stroke in QSqlTableModel by value in the column? Many OPKs would advise users to start using the test strips around day 9 of your cycle, considering day 1 to be the first day of full menstrual flow buy priligy australia
    i
    innorwallNov. 15, 2024, 10:27 a.m.
    Release of C++/Qt and QML application deployment utility CQtDeployer v1.4.0 (Binary Box) optionally substituted alkoxy, optionally substituted alkenyloxy, optionally substituted alkynyloxy, optionally substituted aryloxy, OCH, OC H, OC H, OC H, OC H, OC H, OC H, O C CH, OCH CH OH, O…
    i
    innorwallNov. 15, 2024, 5:26 a.m.
    Qt/C++ - Lesson 031. QCustomPlot – The build of charts with time buy generic priligy We can just chat, and we will not lose too much time anyway
    i
    innorwallNov. 15, 2024, 3:03 a.m.
    Qt/C++ - Lesson 060. Configuring the appearance of the application in runtime I didnt have an issue work colors priligy dapoxetine 60mg revia cost uk August 3, 2022 Reply
    Now discuss on the forum
    t
    tonypeachey1Nov. 15, 2024, 2:04 p.m.
    google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
    i
    innorwallNov. 15, 2024, 1:50 p.m.
    добавить qlineseries в функции priligy for sale Gently flush using an ear syringe
    i
    innorwallNov. 11, 2024, 6:55 p.m.
    Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
    9
    9AnonimOct. 25, 2024, 4:10 p.m.
    Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

    Follow us in social networks