API para Vkontakte
| Grupo | De % |
|---|---|
| Cuenta | 100 |
| Anuncios | 0 |
| AppWidgets | 0 |
| Aplicaciones | 20 |
| Asr | 100 |
| Audio | 79 |
| Auténtico | 100 |
| Junta | 100 |
| Base de datos | 100 |
| Documento | 100 |
| Desgloses | 100 |
| Favorito | 100 |
| Amigos | 100 |
| Regalos | 100 |
| Grupos | 100 |
| Forma de liderazgo | 0 |
| Dirige | 0 |
| Gustos | 100 |
| Mercado | 100 |
| Mensajes | 100 |
| Alimento para noticias | 100 |
| Notas | 100 |
| Notificaciones | 100 |
| Órdenes | 25 |
| Páginas | 100 |
| Fotos | 100 |
| Podcasts | 100 |
| Centro | 100 |
| CONDICIAS BIENES | 0 |
| Buscar | 100 |
| Seguro | 100 |
| Estadísticas | 100 |
| Estado | 100 |
| Almacenamiento | 100 |
| Historias | 100 |
| Transmisión | 100 |
| Usuarios | 100 |
| Tensiones | 100 |
| Video | 100 |
| Muro | 100 |
| Widgets | 0 |
Notas
Para algunas versiones antiguas del entorno, se requiere indicar la directiva de Old_version .
Nota
Para versiones IDE antiguas, incluya la directiva Old_Version
1. Autorización a través de OAuth2 Form
Для FMX - VK.FMX.OAuth2 - TFormFMXOAuth2
Для VCL - VK.VCL.OAuth2 - TFormOAuth2
...
var
FToken: string;
FChangePasswordHash: string;
FTokenExpiry: Int64;
...
procedure TFormMain.VKAuth (Sender: TObject; Url: string; var Token: string; var TokenExpiry: Int64; var ChangePasswordHash: string);
begin
if FToken.IsEmpty then
begin
TFormFMXOAuth2.Execute(Url,
procedure(Form: TFormFMXOAuth2)
begin
FToken := Form.Token;
FTokenExpiry := Form.TokenExpiry;
FChangePasswordHash := Form.ChangePasswordHash;
if not FToken.IsEmpty then
VK.Login;
end );
end
else
begin
Token := FToken;
TokenExpiry := FTokenExpiry;
end ;
end ;
VK.Login(<родитель для окна для VCL, необяз.>);
2. Autorización directamente usando token (usuario o bot)
procedure TFormMain.VKAuth (Sender: TObject; Url: string; var Token: string; var TokenExpiry: Int64; var ChangePasswordHash: string);
begin
Token := ' <здесь токен> ' ;
end ; 3. Autorización utilizando claves de servicio (indicadas en el componente de diseño de diseño)
4. Autorización directa (beta)
VKAPI.Application := TVkApplicationData.Android; < -- Данные оф. клиента для Android
VKAPI.Login( ' +7********** ' , ' ***************** ' ,
function( var Code: string): Boolean
begin
Code := InputBox( ' ' , ' ' , ' ' ); < -- Код двухэтапной авторизации
Result := not Code.IsEmpty;
end ); program VKBotTemplate;
uses
VK.Bot,
VK.Types,
VK.Bot.Utils,
VK.Messages,
VK.GroupEvents,
VK.Entity.Message,
VK.Entity.ClientInfo;
var
VKBot: TVkBotChat;
begin
VKBot := TVkBotChat.GetInstance( 12345678 , ' <token> ' );
with VKBot do
try
OnMessage :=
procedure(Bot: TVkBot; GroupId: Integer; Message: TVkMessage; ClientInfo: TVkClientInfo)
begin
if PeerIdIsUser(Message.PeerId) then
begin
if Assigned(Message.Action) then
case Message.Action.& Type of
TVkMessageActionType.ChatInviteUser:
Bot.API.Messages.SendToPeer(Message.PeerId, ' Welcome ' );
end
else
Bot.API.Messages.SendToPeer(Message.PeerId, ' Your message: ' + Message.Text);
end ;
end ;
if Init and Run then
begin
Console.Run(
procedure( const Command: string; var Quit: Boolean)
begin
Quit := Command = ' exit ' ;
end );
end
else
Readln;
finally
Free;
end ;
end .Obtener usuarios
var
Users: TVkProfiles;
i: Integer;
begin
if VK.Users.Get(Users, [ 286400863 , 415730216 ], TVkProfileFields. All ) then
begin
for i := Low(Users.Items) to High(Users.Items) do
begin
Memo1.Lines.Add( ' About: ' + Users.Items[i].About);
Memo1.Lines.Add( ' BirthDate: ' + Users.Items[i].BirthDate);
Memo1.Lines.Add( ' Domain: ' + Users.Items[i].Domain);
Memo1.Lines.Add( ' FirstName: ' + Users.Items[i].FirstName);
Memo1.Lines.Add( ' Movies: ' + Users.Items[i].Movies);
Memo1.Lines.Add( ' ------------ ' );
end ;
Users.Free;
end ;
end ;Instalación del estado en línea
if VK.Account.SetOnline then
Memo1.Lines.Add( ' online ' )
else
Memo1.Lines.Add( ' Error online ' );Creación de una publicación en un grupo
var
Params: TVkWallParams;
begin
Params.Message( ' Test Text ' );
Params.OwnerId(- 145962568 );
Params.FromGroup(True);
Params.Signed(True);
Params.Attachments([Attachment.Doc( 58553419 , 533494309 , ' 657138cd5d7842ae0a ' )]);
VK.Wall.Post(Params);
end ; Enviando el mensaje
Vk.Messages.Send.PeerId(Message.PeerId).Message(FAnswer).Send.Free;O, con la creación del teclado
var
Keys: TVkKeyboardConstructor;
begin
Keys.SetOneTime(True);
Keys.AddButtonText( 0 , ' Погода ' , ' weather ' , bcPositive);
Keys.AddButtonText( 0 , ' Отмена ' , ' cancel ' , bcNegative);
Keys.AddButtonText( 1 , ' Информация ' , ' info ' , bcPrimary);
Keys.AddButtonText( 1 , ' Команды ' , ' commands ' , bcSecondary);
Vk.Messages.New.
PeerId(PeerId).
Keyboard(Keys).
Message( ' Выбери вариант ' ).
Send;
end ;O simple
VK.Messages.Send(PeerId, ' Текст сообщения ' , [<вложения>]);Envío de foto
VK.Messages.New.UserId( 58553419 ).AddPhotos([ ' D:Downloads6q8q9f.gif ' ]).Send;Obtener grabaciones de audio de una lista de reproducción (álbum)
var
List: TVkAudios;
Params: TVkParamsAudio;
begin
Params.OwnerId( 415730216 );
Params.AlbumId( 86751037 );
if VK.Audio.Get(List, Params) then
try
for var i := Low(List.Items) to High(List.Items) do
Memo1.Lines.Add(List.Items[i].Artist + ' - ' + List.Items[i].Title);
finally
List.Free;
end ;
end ; Uso del método Walk para realizar métodos con parámetros de conteo y compensación
Este es un ciclo simple que causa nuestro método regulando el desplazamiento. Cancelar le permite terminar el ciclo hasta el final de todo el bypass
El método le permite obtener todos los elementos de un determinado método con recuento y desplazamiento lo suficiente como para escribir un diseño estándar de datos que obtiene el método deseado dentro de la función anónima transmitida en Walk e indicar el paso de obtener el número de elementos.
VKAPI.Walk(
function(Offset: Integer; var Cancel: Boolean): Integer
var
Audio: TVkAudio;
Audios: TVkAudios;
Params: TVkParamsAudio;
begin
Result := 0 ; // Метод должн вернуть кол-во фактически полученных элементов
Params.Count( 100 );
Params.Offset(Offset);
if VKAPI.Audio.Get(Audios, Params) then
begin
Result := Length(Audios.Items); // Возвращение кол-во полученных элементов
for Audio in Audios.Items do
begin
// Do somethings with Audio
end ;
Audios.Free;
end
else
Cancel := True;
end , 100 ); // 100 - параметр шага запроса, должен соответстовать параметру метода "Params.Count(100);"