Помогите С Авторизацией Вконтакте. Компонент (idhttp)

Статус
В этой теме нельзя размещать новые ответы.

Андрей

Принятый Кодер
Ofline
Необъявленный идентификатор 'PosEx'
Я прокомментировал в коде ошибку

Код:
unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdCookieManager, IdIOHandler,
  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, sGroupBox,
  sButton, sEdit, Jpeg, Vcl.ExtCtrls;

type
  TForm2 = class(TForm)
    sEdit1: TsEdit;
    sEdit2: TsEdit;
    sButton1: TsButton;
    sGroupBox1: TsGroupBox;
    sButton2: TsButton;
    sButton3: TsButton;
    sButton4: TsButton;
    sButton5: TsButton;
    IdHTTP1: TIdHTTP;
    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
    IdCookieManager1: TIdCookieManager;
    Image1: TImage;
    procedure sButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.sButton1Click(Sender: TObject);
var data:tstringlist;
      PageProfile, pic:string;
      error:boolean;
      beginpos, endpos : Integer;
  ms:   TMemoryStream;
  jpeg: TJpegImage;
begin
IdHTTP1.AllowCookies:=true;
IdHTTP1.HandleRedirects:=false;
data:=tstringlist.create;
data.Add('email=sEdit1.text');
data.Add('pass=sEdit2.text');
data.Add('expire=');
data.Add('vk=');
error:=false;
try
  PageProfile:=IdHTTP1.Post('http://login.vk.com/?act=login', data);
except
  error:=true;
end;

if not(error) then
  begin
   data.Clear;
   data.Add('s='+Copy(PageProfile, Pos('value', PageProfile)+7, 56));
   data.Add('op=slogin');
   data.Add('redirect=1');
   data.Add('expire=0');
   data.Add('to=');
   IdHTTP1.HandleRedirects:=true;
   try
    PageProfile:=IdHTTP1.Post('http://vk.com/login.php', data);
   except
   end;
   beginpos := Pos('center', PageProfile);
   endpos := PosEx('/>', PageProfile, beginpos + 21); // PosEx тут подчеркнуто красным.
   pic := Copy(PageProfile, beginpos + 21, endpos - (beginpos + 21));
   ShowMessage(pic);

    ms := TMemoryStream.Create;
    jpeg := TJpegImage.Create;
    try
      IdHTTP1.Get(pic, ms);
      ms.Position := 0;
      jpeg.LoadFromStream(ms);
      Image1.Picture.Graphic := jpeg;
    finally
      jpeg.Free; ms.Free;
    end;
  end
else
  ShowMessage('Авторизация не удалась');

Data.Free;
end;

end.
 
Необъявленный идентификатор 'PosEx'
Я прокомментировал в коде ошибку

Код:
unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdCookieManager, IdIOHandler,
  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, sGroupBox,
  sButton, sEdit, Jpeg, Vcl.ExtCtrls;

type
  TForm2 = class(TForm)
    sEdit1: TsEdit;
    sEdit2: TsEdit;
    sButton1: TsButton;
    sGroupBox1: TsGroupBox;
    sButton2: TsButton;
    sButton3: TsButton;
    sButton4: TsButton;
    sButton5: TsButton;
    IdHTTP1: TIdHTTP;
    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
    IdCookieManager1: TIdCookieManager;
    Image1: TImage;
    procedure sButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.sButton1Click(Sender: TObject);
var data:tstringlist;
      PageProfile, pic:string;
      error:boolean;
      beginpos, endpos : Integer;
  ms:   TMemoryStream;
  jpeg: TJpegImage;
begin
IdHTTP1.AllowCookies:=true;
IdHTTP1.HandleRedirects:=false;
data:=tstringlist.create;
data.Add('email=sEdit1.text');
data.Add('pass=sEdit2.text');
data.Add('expire=');
data.Add('vk=');
error:=false;
try
  PageProfile:=IdHTTP1.Post('http://login.vk.com/?act=login', data);
except
  error:=true;
end;

if not(error) then
  begin
   data.Clear;
   data.Add('s='+Copy(PageProfile, Pos('value', PageProfile)+7, 56));
   data.Add('op=slogin');
   data.Add('redirect=1');
   data.Add('expire=0');
   data.Add('to=');
   IdHTTP1.HandleRedirects:=true;
   try
    PageProfile:=IdHTTP1.Post('http://vk.com/login.php', data);
   except
   end;
   beginpos := Pos('center', PageProfile);
   endpos := PosEx('/>', PageProfile, beginpos + 21); // PosEx тут подчеркнуто красным.
   pic := Copy(PageProfile, beginpos + 21, endpos - (beginpos + 21));
   ShowMessage(pic);

    ms := TMemoryStream.Create;
    jpeg := TJpegImage.Create;
    try
      IdHTTP1.Get(pic, ms);
      ms.Position := 0;
      jpeg.LoadFromStream(ms);
      Image1.Picture.Graphic := jpeg;
    finally
      jpeg.Free; ms.Free;
    end;
  end
else
  ShowMessage('Авторизация не удалась');

Data.Free;
end;

end.

В uses добавь StrUtils
 
В uses добавь StrUtils
Это помогло скомпилировать код, но авторизация не удалась. Что я не сделал еще, или все верно?
DII три файла в папке с проектом.
u5Bpj7cqaco.jpg
 
Последнее редактирование:
Это такой логин, какой добыл аккаунт такой и использую для программ. А вообще на любой аккаунт не работает авторизация.
У тебя же была прога где нормальная авторизация а этот код уже давно не работает
 
У тебя же была прога где нормальная авторизация а этот код уже давно не работает
Мне нужна программа для Online Вконтакте.Та прога авторизовывается через Android, то есть я на сайте сижу через телефон, а мне нужен Online через ПК
 
Статус
В этой теме нельзя размещать новые ответы.
Назад
Сверху Снизу