VK_API
1.0.0
Vkontakte的API
| 團體 | % |
|---|---|
| 帳戶 | 100 |
| 廣告 | 0 |
| AppWidgets | 0 |
| 應用 | 20 |
| ASR | 100 |
| 聲音的 | 79 |
| auth | 100 |
| 木板 | 100 |
| 資料庫 | 100 |
| 文件 | 100 |
| 下載的遊戲 | 100 |
| 最愛 | 100 |
| 朋友們 | 100 |
| 禮物 | 100 |
| 組 | 100 |
| LEADFORMS | 0 |
| 鉛 | 0 |
| 喜歡 | 100 |
| 市場 | 100 |
| 消息 | 100 |
| 新聞源 | 100 |
| 筆記 | 100 |
| 通知 | 100 |
| 訂單 | 25 |
| 頁面 | 100 |
| 照片 | 100 |
| podcast | 100 |
| 民意調查 | 100 |
| 漂亮的卡片 | 0 |
| 搜尋 | 100 |
| 安全的 | 100 |
| 統計 | 100 |
| 地位 | 100 |
| 貯存 | 100 |
| 故事 | 100 |
| 流 | 100 |
| 用戶 | 100 |
| UTILS | 100 |
| 影片 | 100 |
| 牆 | 100 |
| 小部件 | 0 |
筆記
對於某些舊版本的環境,需要指示old_version的指令。
筆記
對於舊的IDE版本,包括Old_version指令
1。通過oauth2表格授權
Для 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。直接使用令牌(用戶或bot)的授權
procedure TFormMain.VKAuth (Sender: TObject; Url: string; var Token: string; var TokenExpiry: Int64; var ChangePasswordHash: string);
begin
Token := ' <здесь токен> ' ;
end ; 3。使用服務鍵的授權(在DesignTime組件中指示)
4。直接授權(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 .獲取用戶
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 ;在線安裝狀態
if VK.Account.SetOnline then
Memo1.Lines.Add( ' online ' )
else
Memo1.Lines.Add( ' Error online ' );在小組中創建帖子
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 ; 發送消息
Vk.Messages.Send.PeerId(Message.PeerId).Message(FAnswer).Send.Free;或者,隨著鍵盤的創建
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 ;或簡單
VK.Messages.Send(PeerId, ' Текст сообщения ' , [<вложения>]);發送照片
VK.Messages.New.UserId( 58553419 ).AddPhotos([ ' D:Downloads6q8q9f.gif ' ]).Send;獲取播放列表的錄音(專輯)
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 ; 使用步行方法執行具有計數和偏移參數的方法
這是一個簡單的循環,可以通過調節偏移來引起我們的方法。取消使您可以完成周期,直到整個旁路結束
該方法允許您獲得具有計數和偏移足夠偏移的某種方法的所有元素,以編寫使用所需方法在步行中傳輸的匿名函數中獲得的數據設計,並指出獲得元素數量的步驟。
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);"