Polya
Принятый Кодер
- Регистрация
- 8 Июн 2016
- Сообщения
- 47
- Баллы
- 50
https://vk.com/doc89488140_437609668
Код:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, httpsend, lib, Json;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Memo1: TMemo;
Edit3: TEdit;
Button2: TButton;
Button3: TButton;
RadioButton1: TRadioButton;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
response, token, uid: string;
function GetFriendsRequests: TStringList;
procedure SubmitFriends(ids: TStringList);
end;
var
Form1: TForm1;
HTTP: thttpsend;
STRTime: string;
s1, AnsiReplaceText: string;
sl: TStringList;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
temp, login, pass: string;
begin
STRTime := TimetoStr(Time);
login := Edit1.text;
pass := Edit2.text;
HTTP := thttpsend.Create;
response := send('GET', 'https://oauth.vk.com/token?grant_type=password&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&username=' + login + '&password=' + pass + '&scope=friends,video,offline&captcha_key=&captcha_sid=' + token);
if Pos('token', response) <> 0 then
begin
temp := copy(response, Pos('access_token":"', response),
Pos('","expires_in', response) - 3);
delete(temp, 1, 15);
token := temp;
Memo1.Lines.Add('Авторизация успешна');
end
else
Memo1.Lines.Add('Ошибка авторизации');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
temp: string;
begin
response := send('GET', 'https://api.vk.com/method/wall.post?message=' + Edit3.text + '&v=5.24&access_token=' + token);
if Pos('post_id', response) <> 0 then
begin
Memo1.Lines.Add('Запись успешно опубликована.' + #13#10 + response);
end
end;
procedure TForm1.Button3Click(Sender: TObject);
const DelSym = ' .,!?';
var
temp, s2, s3: string;
Text,Word,LongestWord: string; i: integer;
begin
response := send('GET', 'https://api.vk.com/method/friends.getRequests?offset&count&out&extended&v=5.24&access_token=' + token);
if Pos('count', response) <> 0 then
begin
s1 := copy(response, Pos('"items":', response));
delete(s1, 1, 9);
token := s1;
Memo1.Lines.Add(s1);
Text:=Memo1.Lines.Text;
for i := 1 to Length(Text) do
if Pos(Text[i],DelSym) > 0 then
Text[i]:=',';
if Text[1] = ',' then
Delete(Text,1,1);
while Pos(',,',Text) > 0 do
Delete(Text,Pos(',,',Text),1);
Text:=AnsiReplaceText(Text,Chr(13),'');
Text:=AnsiReplaceText(Text,Chr(10),'');
repeat
Word:=Copy(Text,1,Pos(',',Text)-1);
Delete(Text,1,Length(Word)+1);
ListBox1.Items.Add(Word);
until Length(Text) = 0;
Label1.Caption:='Количество слов в тексте: '+IntToStr(ListBox1.Items.Count);
LongestWord:=ListBox1.Items[0];
for i := 1 to ListBox1.Items.Count-1 do
if Length(ListBox1.Items[i]) > Length(LongestWord) then
LongestWord:=ListBox1.Items[i];
Label2.Caption:='Самое длинное слово: '+LongestWord+' ('+IntToStr(Length(LongestWord))+' букв)';
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
temp, s2, s3: string;
i: integer;
begin
response := send('GET', 'https://api.vk.com/method/friends.getRequests?offset&count&out&extended&v=5.24&access_token=' + token);
if Pos('count', response) <> 0 then
begin
s1 := copy(response, Pos('"items":', response));
delete(s1, 1, 9);
if Pos(',', response) <> 0 then
for i := length(s1) downto 1 do
if s1[i] = '.' then
insert(#13 + #10, s1, i + 1);
token := s1;
ListBox1.Items.Add(s1);
end
//if Pos(',', response) <> 0 then
//SubmitFriends(GetFriendsRequests);
end;
function TForm1.GetFriendsRequests: TStringList;
var
temp, s2, s3: string;
i: integer;
begin
result := TStringList.Create;
response := send('GET', 'https://api.vk.com/method/friends.getRequests?offset&count&out&extended&v=5.24&access_token=' + token);
if Pos('count', response) <> 0 then
begin
s1 := copy(response, Pos('"items":', response));
delete(s1, 1, 9);
for i := length(s1) downto 1 do
if s1[i] = '.' then
insert(#13 + #10, s1, i + 1);
token := s1;
result.Add(s1);
end
end;
procedure TForm1.SubmitFriends(ids: TStringList);
var
FriendsRequests: TStringList;
id: string;
begin
FriendsRequests := GetFriendsRequests;
for id in FriendsRequests do
if RadioButton1.Checked=true then begin
response := send('GET', 'https://api.vk.com/method/friends.add?user_id='+id+'&v=5.24&access_token=' + token);
FriendsRequests.Destroy;
end;
end;
end.
Последнее редактирование: