Konuyu Oyla:
  • Derecelendirme: 4/5 - 2 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Delphi İle Instagram'da Otomatik Paylaşım
#1
Merhabalar;

Bir program yazmaya çalışıyorum. Belirleyeceğim bir klasörün içindeki resimleri, belirleyeceğim zaman aralıklarında, belirleyeceğim etiketlerle sosyal medya'da paylaşımı sağlayacak.
Öncelikle instagram ile başlamak istedim. Tabi bunun için öncelikle login olmak gerekiyor. Araştırmalarım sonucunda bir çok koda ve önerilere rastladım fakat hiç birinden sonuç alamadım.

Örneğin aşağıdaki kodlarda token alma, idhttp ile bağlanma, netclient ile bağlanma ve web browser ile bağlanmaya çalıştım. 
Twebbrowser ile bağlanmada operation pointer hatası veriyor (Bu seçenekte giriş yapıyor fakat benim yazdığım kullacıya değil de açık olan kullanıcıya bağlanıyor)
idhttp ile bağlanmada bad request hatası veriyor.
netclient bağlanmada operation pointer hatası veriyor.
token al'da ise hiç hata vermiyor takılıp kalıyor.

Sadece login için yardımcı olur musunuz?



unit fmfb;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls, OleCtrls, SHDocVw, Vcl.ExtCtrls, System.Net.URLClient,
 System.Net.HttpClient, System.Net.HttpClientComponent, IdCookie,
 IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
 IdServerIOHandler, IdSSL, IdSSLOpenSSL, IdIOHandlerSocket,
 IdIOHandlerStack, IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer, Vcl.Buttons,
 IdURI, IdCookieManager;

type
TForm1 = class(TForm)
   Panel2: TPanel;
   Button1: TButton;
   Web: TWebBrowser;
   Panel1: TPanel;
   Edit1: TEdit;
   Edit2: TEdit;
   Button2: TButton;
   Memo1: TMemo;
   Button3: TButton;
   Button4: TButton;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
   procedure Button3Click(Sender: TObject);
   procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MySSL: TIdSSLIOHandlerSocketOpenSSL;
HTTP: TIdHTTP;
IdCookieManager1: TIdCookieManager;

implementation
{$R *.dfm}


function HTMLDecode(const AStr: String): String;
var
 Sp, Rp, Cp, Tp: PChar;
 S: String;
 I, Code: Integer;
begin
 SetLength(Result, Length(AStr));
 Sp := PChar(AStr);
 Rp := PChar(Result);
 Cp := Sp;
 try
 while Sp^ <> #0 do
 begin
 case Sp^ of
 '&': begin
 Cp := Sp;
 Inc(Sp);
 case Sp^ of
 'a': if AnsiStrPos(Sp, 'amp;') = Sp then { do not localize }
 begin
 Inc(Sp, 3);
 Rp^ := '&';
 end;
 'l',
 'g': if (AnsiStrPos(Sp, 'lt;') = Sp) or (AnsiStrPos(Sp, 'gt;') = Sp) then { do not localize }
 begin
 Cp := Sp;
 Inc(Sp, 2);
 while (Sp^ <> ';') and (Sp^ <> #0) do
 Inc(Sp);
 if Cp^ = 'l' then
 Rp^ := '<'
 else
 Rp^ := '>';
 end;
   'n': if AnsiStrPos(Sp, 'nbsp;') = Sp then { do not localize }
 begin
   Inc(Sp, 4);
   Rp^ := ' ';
 end;
   'q': if AnsiStrPos(Sp, 'quot;') = Sp then { do not localize }
 begin
   Inc(Sp,4);
   Rp^ := '"';
 end;
 '#': begin
   Tp := Sp;
   Inc(Tp);
 while (Sp^ <> ';') and (Sp^ <> #0) do
   Inc(Sp);
   SetString(S, Tp, Sp - Tp);
   Val(S, I, Code);
   Rp^ := Chr((I));
 end;
 else
   Exit;
 end;
 end
 else
   Rp^ := Sp^;
 end;
   Inc(Rp);
   Inc(Sp);
 end;
 except
 end;
 SetLength(Result, Rp - PChar(Result));
end;

function Pars(T_, ForS, _T: string): string;
var a, b:integer;
begin
 Result := '';
 if (T_='') or (ForS='') or (_T='') then Exit;
 a:=Pos(T_, ForS);
 if a=0 then Exit else a:=a+Length(T_);
 ForS:=Copy(ForS, a, Length(ForS)-a+1);
 b:=Pos(_T, ForS);
 if b>0 then
 Result:=Copy(ForS, 1, b - 1);
end;

function Auth(LoginString:string;OAuth_token:string):Boolean;
var s:TStringStream;
   res,middlewaretoken, home, key:string;
   han:Boolean;
   Data:TStringList;
   uri:TIdURI;
   HTTP:TidHTTP;
begin
 Result:=False;
 s:=TStringStream.Create('');
 Data:=TStringList.Create;
 uri:=TIdURI.Create('https://instagram.com');
 try

   HTTP := TidHTTP.Create(nil);
   MySSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
   han := HTTP.HandleRedirects;
   HTTP.HandleRedirects:=True;
   HTTP.Request.Referer:='https://instagram.com/accounts/login/?next=/oauth/authorize/%3Fclient_id%3D'+OAuth_Token+'%26redirect_uri%3Dht  tp%3A//localhost%26response_type%3Dtoken%26scope%3Drelations  hips';
   s.Size:=0;
   try
   HTTP.IOHandler:=MySSL;
   HTTP.Get('https://api.instagram.com/oauth/authorize/?client_id='+OAuth_token+'&redirect_uri='+'http://localhost'+'&response_type=token&scope=relationships+likes+comments',s);
   except
   end;
   res:=s.DataString;
   middlewaretoken:=Pars('<input type="hidden" name="csrfmiddlewaretoken" value="',res,'"');
   Data.Add('csrfmiddlewaretoken='+middlewaretoken);
   Data.Add('username='+Trim(Copy(LoginString,1,Pos('  :',LoginString)-1)));
   Data.Add('password='+Trim(Copy(LoginString,Pos(':'  ,LoginString)+1,Length(LoginString))));

   HTTP.Request.CustomHeaders.AddValue('Accept-Language', 'ru-RU');
   HTTP.Request.CustomHeaders.AddValue('Referer', 'https://instagram.com/');

   s.Size:=0;
   HTTP.HandleRedirects:=False;
   try
  HTTP.Post('https://instagram.com'+Pars('<form method="POST" id="login-form" class="adjacent" action="',res,'"'),Data,s);
   except
     on E:EIdHTTPProtocolException do
     begin

       if (E.ErrorCode=302)and(Pos('access_token=',HTTP.Response.Location)>0) then
       begin
         key:=Pars('access_token=',HTTP.Response.Location,  '');
         Result:=True;
         Exit;
       end
       else
       if (e.ErrorCode=302) then
       try
         HTTP.HandleRedirects:=True;
         try
           HTTP.Get(HTTP.Response.Location,s);
         except
         end;
       finally
         HTTP.HandleRedirects:=False;
       end;
     end;
     on E:Exception do;
   end;
   res:=s.DataString;
   Data.Clear;
   Data.Add('csrfmiddlewaretoken='+middlewaretoken);
   Data.Add('allow=Authorize');
   try
     HTTP.Post('https://instagram.com/oauth/authorize/?client_id='+OAuth_Token+'&redirect_uri=http://localhost&response_type=token&scope=relationships+likes+comments',Data,s);
   except
     on E:EIdHTTPProtocolException do
     begin
       if (E.ErrorCode=302)and(Pos('access_token=',HTTP.Response.Location)>0) then
       begin
       showmessage('true');
         key:=Pars('access_token=',HTTP.Response.Location,  '');
         Result:=True;
         Exit;
       end
       else
       if (e.ErrorCode=302) then
       try
       showmessage('false');
         HTTP.Get(HTTP.Response.Location,s);
       except
       end;
     end;
     on E:Exception do;
   end;
 finally
   HTTP.HandleRedirects:=han;
   Data.Free;
   uri.Free;
   s.Free;
 end;
end;

procedure WB_send_Click_by_Value(WB: TWebbrowser;form_nr:nativeint;tag,typ,val: string);
var ovElements: OleVariant;
i : integer;
Begin
 ovElements := WB.OleObject.Document.forms.item(form_nr).elements;
 for i := 0 to (ovElements.Length - 1) do
 begin
   if AnsiSameText(ovElements.item(i).tagName,tag) and
   AnsiSameText(ovElements.item(i).type,typ) and
   AnsiSameText(ovElements.item(i).value,val) then
   ovElements.item(i).Click;
 end;
End;


procedure TForm1.Button1Click(Sender: TObject);
var
 gelen,gelen2,gelen3:string;
 label
 bagli;
begin
 web.Navigate('https://www.instagram.com/accounts/login/?force_classic_login');
 while web.ReadyState <> READYSTATE_COMPLETE do
 begin
 sleep(1);
 Application.ProcessMessages;
 end;
 Web.OleObject.Document.GetElementByid('email').value:=edit1.Text;
 Web.OleObject.Document.GetElementByid('pass').value:=edit2.Text;
 WB_send_Click_by_Value(Web,0,'input','submit','Giriş Yap');
end;


procedure TForm1.Button2Click(Sender: TObject);
var
 lHTTP: TNetHTTPClient;
 httpreq: TNetHTTPRequest;
 Params : TStrings;
 Reply, Token: string;
 s : TNetHeaders;
 sReq : TStringStream;
//  XSO : ISuperObject;
begin
 Params := TStringList.Create;
 try
   Params.Add('username=' + Edit1.Text);
   Params.Add('password=' + Edit2.Text);

   lHTTP := TNetHTTPClient.Create(nil);
   try
     lHTTP.HandleRedirects := True;
     lHTTP.Get('https://www.instagram.com', TStream(nil));
     lHTTP.AllowCookies := True;
     lHTTP.ContentType := 'application/x-www-form-urlencoded';
     lHTTP.UserAgent := 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36';

     Token := lHTTP.CookieManager.Cookies[0].Value;

     sReq := TStringStream.Create(Memo1.Text,TEncoding.UTF8);
     sReq.Position := 0;
     SetLength(s,5);
     s[0].Name := 'X-CSRFToken';
     s[0].Value := 'www.instagram.com' + Token;
     s[1].Name := 'username=';
     s[1].Value := Edit1.Text;
     s[2].Name := 'password=';
     s[2].Value := Edit2.Text;
     s[3].Name := 'X-Instagram-AJAX';
     s[3].Value := '1';
     s[4].Name := 'X-Requested-With';
     s[4].Value := 'XMLHttpRequest';
     s[5].Name := 'Referer';
     s[5].Value := 'https://www.instagram.com/';
       Reply := lHTTP.Post('https://www.instagram.com/accounts/login/ajax/','',Nil,s).ContentAsString(TEncoding.UTF8);
       Reply := '{"arr":'+Reply+'}';
//        XSO := SO(Reply);
     Memo1.Text := Reply;
   finally
     lHTTP.Free;
   end;
 finally
   Params.Free;
 end;
end;




procedure TForm1.Button3Click(Sender: TObject);
var
 lHTTP: TIdHTTP;
 IdSSL: TIdSSLIOHandlerSocketOpenSSL;
 Params : TStrings;
 Reply, Token: string;
 Cookie: TIdCookie;
begin
 Params := TStringList.Create;
 try
   Params.Add('username=' + Edit1.Text);
   Params.Add('password=' + Edit2.Text);

   lHTTP := TIdHTTP.Create(nil);
   try
     IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);
     IdSSL.SSLOptions.Method := sslvTLSv1;
     IdSSL.SSLOptions.Mode := sslmClient;
     lHTTP.IOHandler := IdSSL;

     lHTTP.ReadTimeout := 30000;
     lHTTP.HandleRedirects := True;

     // capture cookies first...
     // passing nil to ignore any response body data and not waste memory for it...
     lHTTP.Request.UserAgent := 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36';
     lHTTP.Get('https://www.instagram.com', TStream(nil));

     Cookie := lHTTP.CookieManager.CookieCollection.Cookie['csrftoken', 'www.instagram.com'];
     if Cookie <> nil then
       Token := Cookie.Value;

     // now submit the login webform...
     lHTTP.Request.CustomHeaders.Values['X-CSRFToken'] := '8b474ece03msh51596fb843650d4p1d6533jsn0ad338e3d755';
     lHTTP.Request.CustomHeaders.Values['X-Instagram-AJAX'] := '1';
     lHTTP.Request.CustomHeaders.Values['X-Requested-With'] := 'XMLHttpRequest';
     lHTTP.Request.Referer := 'https://www.instagram.com/';
     lHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
     lHTTP.Request.UserAgent := 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36';
     Reply := lHTTP.Post('https://instagram.com/accounts/login/', Params);
     Memo1.Text := Reply;
   finally
     lHTTP.Free;
   end;
 finally
   Params.Free;
 end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
     Auth('login:xxxxxxxxx','OAuth_Token');
end;

end.

Cevapla
#2
instagram kullanmiyorum ama api destegi varmis.
https://www.delphican.com/archive/index....-2117.html
https://github.com/blogjonathanschmitt/d...tagram-api
Belki isinize yarar.
Cevapla
#3
Merhaba.

Aşağıdaki gibi yapı işinizi görecektir. Bu şekilde kullanıyorum.



uses  System.Net.HttpClientComponent,
      System.JSON,
      System.Generics.Collections,
      System.DateUtils,
      System.UITypes;

Type
  tInstagramInfo = Record
    csrf_token,
    timestamp,
    username,
    password,
    userId,
    user,
    authenticated,
    oneTapPrompt,
    message_,
    status        : string;
  end;

var
  FInstaInfo : tInstagramInfo;

procedure LoginInstagram();
const
  LLogin          = 'https://www.instagram.com/accounts/login/';
  LLoginAjax      = 'https://www.instagram.com/accounts/login/ajax/';
  LUserAgent      = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36';
var
  LClient     : System.Net.HttpClientComponent.TNetHTTPClient;
  LResponse   : String;
  LJSONData   : TJSONValue;
  Lconfig     : TJSONValue;
  Lcsrf_token : TJSONValue;
  LPostData   : TStringList;
begin
  FInstaInfo.timestamp  := IntToStr( DateTimeToUnix( Now() ) );
  LClient := TNetHTTPClient.Create(nil);
  try
    LClient.UserAgent  := LUserAgent;
    LResponse := LClient.Get( LLogin ).ContentAsString;
    if Pos('window._sharedData', LResponse) > 0 then
    begin
      System.Delete( LResponse, 1, Pos('window._sharedData', LResponse) );
      System.Delete( LResponse, 1, Pos('{', LResponse) -1 );
      LResponse := Copy(LResponse, 1, pos(';</', LResponse )-1 );

      LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
      try
        if LJSONData <> nil then begin
          Lconfig := TJSONObject(LJSONData).Get('config').JsonValue;
          if LConfig <> nil then begin
            Lcsrf_token := TJSONObject(Lconfig).Get('csrf_token').JsonValue;
            if Lcsrf_token <> nil
              then FInstaInfo.csrf_token := Lcsrf_token.Value;
          end;
        end;
      finally
        LJSONData.Free;
      end;

      LClient.CustHeaders.Clear;
        LClient.CustomHeaders['x-requested-with'] := 'XMLHttpRequest';
        LClient.CustomHeaders['referer']          := LLogin;
        LClient.CustomHeaders['x-csrftoken']      := FInstaInfo.csrf_token;

      LPostData := TStringList.Create;
      try
        LPostData.Values['username']      := FInstaInfo.username;
        LPostData.Values['enc_password']  := Format('#PWD_INSTAGRAM_BROWSER:0:%s:%s', [ FInstaInfo.timestamp, FInstaInfo.password ]);
        LPostData.Values['queryParams']   := '{}';
        LPostData.Values['optIntoOneTap'] := 'false';

        LResponse := LClient.Post( LLoginAjax, LPostData ).ContentAsString;

        LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
        try
          if LJSONData <> nil then begin
            FInstaInfo.status         := TJSONObject(LJSONData).Get('status').JsonValue.Value;
            if FInstaInfo.status = 'ok' then begin
              FInstaInfo.user           := TJSONObject(LJSONData).Get('user').JsonValue.Value;
              FInstaInfo.authenticated  := TJSONObject(LJSONData).Get('authenticated').JsonValue.Value;
              if TJSONObject(LJSONData).FindValue('userId') <> nil
                then FInstaInfo.userId         := TJSONObject(LJSONData).Get('userId').JsonValue.Value;
              if TJSONObject(LJSONData).FindValue('oneTapPrompt') <> nil
                then FInstaInfo.oneTapPrompt   := TJSONObject(LJSONData).Get('oneTapPrompt').JsonValue.Value;
            end else begin
              if TJSONObject(LJSONData).FindValue('message') <> nil
                then FInstaInfo.message_     := TJSONObject(LJSONData).Get('message').JsonValue.Value;
            end;
          end;
        finally
          LJSONData.Free;
        end;
      finally
        FreeAndNil( LPostData );
      end;
    end;
  finally
    FreeAndNil( LClient );
  end;
end;




Kullanımı :
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  FInstaInfo := default( tInstagramInfo );
  FInstaInfo.username   := 'KullanıcıAdı';
  FInstaInfo.password   := 'Parola';

  LoginInstagram();

  if FInstaInfo.status = 'ok' then
  begin
    if ( FInstaInfo.user = 'false' )
    then
      MessageDlg( FInstaInfo.username + ' kullanıcısı mevcut değil', TMsgDlgType.mtError, [mbOk], 0 )
    else
    if ( FInstaInfo.user = 'true' ) and ( FInstaInfo.authenticated = 'false' )
    then
      MessageDlg( FInstaInfo.username + ' parolası hatalı', TMsgDlgType.mtError, [mbOk], 0 )
    else
    if ( FInstaInfo.user = 'true' ) and ( FInstaInfo.authenticated = 'true' )
    then
      MessageDlg( 'UserId : ' + FInstaInfo.userId, TMsgDlgType.mtInformation, [mbOk], 0 )
    else
      MessageDlg( 'Başka bir sorun oldu.', TMsgDlgType.mtError, [mbOk], 0 );
  end else begin
    MessageDlg( 'Mesaj : ' + FInstaInfo.message_, TMsgDlgType.mtError, [mbOk], 0 );
  end;
end;

Saygılarımla
Muharrem ARMAN

guplouajuixjzfm15eqb.gif
Cevapla
#4
(18-05-2021, Saat: 23:03)mrmarman Adlı Kullanıcıdan Alıntı: Merhaba.

Aşağıdaki gibi yapı işinizi görecektir. Bu şekilde kullanıyorum.



uses  System.Net.HttpClientComponent,
      System.JSON,
      System.Generics.Collections,
      System.DateUtils,
      System.UITypes;

Type
  tInstagramInfo = Record
    csrf_token,
    timestamp,
    username,
    password,
    userId,
    user,
    authenticated,
    oneTapPrompt,
    message_,
    status        : string;
  end;

var
  FInstaInfo : tInstagramInfo;

procedure LoginInstagram();
const
  LLogin          = 'https://www.instagram.com/accounts/login/';
  LLoginAjax      = 'https://www.instagram.com/accounts/login/ajax/';
  LUserAgent      = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36';
var
  LClient     : System.Net.HttpClientComponent.TNetHTTPClient;
  LResponse   : String;
  LJSONData   : TJSONValue;
  Lconfig     : TJSONValue;
  Lcsrf_token : TJSONValue;
  LPostData   : TStringList;
begin
  FInstaInfo.timestamp  := IntToStr( DateTimeToUnix( Now() ) );
  LClient := TNetHTTPClient.Create(nil);
  try
    LClient.UserAgent  := LUserAgent;
    LResponse := LClient.Get( LLogin ).ContentAsString;
    if Pos('window._sharedData', LResponse) > 0 then
    begin
      System.Delete( LResponse, 1, Pos('window._sharedData', LResponse) );
      System.Delete( LResponse, 1, Pos('{', LResponse) -1 );
      LResponse := Copy(LResponse, 1, pos(';</', LResponse )-1 );

      LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
      try
        if LJSONData <> nil then begin
          Lconfig := TJSONObject(LJSONData).Get('config').JsonValue;
          if LConfig <> nil then begin
            Lcsrf_token := TJSONObject(Lconfig).Get('csrf_token').JsonValue;
            if Lcsrf_token <> nil
              then FInstaInfo.csrf_token := Lcsrf_token.Value;
          end;
        end;
      finally
        LJSONData.Free;
      end;

      LClient.CustHeaders.Clear;
        LClient.CustomHeaders['x-requested-with'] := 'XMLHttpRequest';
        LClient.CustomHeaders['referer']          := LLogin;
        LClient.CustomHeaders['x-csrftoken']      := FInstaInfo.csrf_token;

      LPostData := TStringList.Create;
      try
        LPostData.Values['username']      := FInstaInfo.username;
        LPostData.Values['enc_password']  := Format('#PWD_INSTAGRAM_BROWSER:0:%s:%s', [ FInstaInfo.timestamp, FInstaInfo.password ]);
        LPostData.Values['queryParams']   := '{}';
        LPostData.Values['optIntoOneTap'] := 'false';

        LResponse := LClient.Post( LLoginAjax, LPostData ).ContentAsString;

        LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
        try
          if LJSONData <> nil then begin
            FInstaInfo.status         := TJSONObject(LJSONData).Get('status').JsonValue.Value;
            if FInstaInfo.status = 'ok' then begin
              FInstaInfo.user           := TJSONObject(LJSONData).Get('user').JsonValue.Value;
              FInstaInfo.authenticated  := TJSONObject(LJSONData).Get('authenticated').JsonValue.Value;
              if TJSONObject(LJSONData).FindValue('userId') <> nil
                then FInstaInfo.userId         := TJSONObject(LJSONData).Get('userId').JsonValue.Value;
              if TJSONObject(LJSONData).FindValue('oneTapPrompt') <> nil
                then FInstaInfo.oneTapPrompt   := TJSONObject(LJSONData).Get('oneTapPrompt').JsonValue.Value;
            end else begin
              if TJSONObject(LJSONData).FindValue('message') <> nil
                then FInstaInfo.message_     := TJSONObject(LJSONData).Get('message').JsonValue.Value;
            end;
          end;
        finally
          LJSONData.Free;
        end;
      finally
        FreeAndNil( LPostData );
      end;
    end;
  finally
    FreeAndNil( LClient );
  end;
end;




Kullanımı :
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  FInstaInfo := default( tInstagramInfo );
  FInstaInfo.username   := 'KullanıcıAdı';
  FInstaInfo.password   := 'Parola';

  LoginInstagram();

  if FInstaInfo.status = 'ok' then
  begin
    if ( FInstaInfo.user = 'false' )
    then
      MessageDlg( FInstaInfo.username + ' kullanıcısı mevcut değil', TMsgDlgType.mtError, [mbOk], 0 )
    else
    if ( FInstaInfo.user = 'true' ) and ( FInstaInfo.authenticated = 'false' )
    then
      MessageDlg( FInstaInfo.username + ' parolası hatalı', TMsgDlgType.mtError, [mbOk], 0 )
    else
    if ( FInstaInfo.user = 'true' ) and ( FInstaInfo.authenticated = 'true' )
    then
      MessageDlg( 'UserId : ' + FInstaInfo.userId, TMsgDlgType.mtInformation, [mbOk], 0 )
    else
      MessageDlg( 'Başka bir sorun oldu.', TMsgDlgType.mtError, [mbOk], 0 );
  end else begin
    MessageDlg( 'Mesaj : ' + FInstaInfo.message_, TMsgDlgType.mtError, [mbOk], 0 );
  end;
end;


Muharrem Hocam cevap için çok teşekkür ederim. 


if TJSONObject(LJSONData).FindValue('userId') <> nil bu satırda (E2362 Korumalı sembol TJSONObject.FindValue erişilemiyor) hatası veriyor. Kontrolleri kaldırdım çalıştı. Tekrar teşekkür ederim.
Saygılarımla;
Cevapla
#5
Eski sürüm Delphi olmalı.

* Kontroller önemli iki ihtimalli sonuç dönüyor çünkü...

Aşağıdaki şekilde deneyin. Bu defa önce ara demiyoruz TryGetValue şeklinde almaya çalışıp alınabildiyse sonucu yönlendiriyoruz.
* Güncelleme anlaşılsın diye orjinal hallerine // ile comment tagına alıp altlarına uyumlusunu yazdım.



procedure LoginInstagram();
const
  LLogin          = 'https://www.instagram.com/accounts/login/';
  LLoginAjax      = 'https://www.instagram.com/accounts/login/ajax/';
  LUserAgent      = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36';
var
  LClient     : System.Net.HttpClientComponent.TNetHTTPClient;
  LResponse   : String;
  LJSONData   : TJSONValue;
  Lconfig     : TJSONValue;
  Lcsrf_token : TJSONValue;
  LPostData   : TStringList;
  LDummyValue : TJSONValue;
begin
  FInstaInfo.timestamp  := IntToStr( DateTimeToUnix( Now() ) );
  LClient := TNetHTTPClient.Create(nil);
  try
    LClient.UserAgent  := LUserAgent;
    LResponse := LClient.Get( LLogin ).ContentAsString;
    if Pos('window._sharedData', LResponse) > 0 then
    begin
      System.Delete( LResponse, 1, Pos('window._sharedData', LResponse) );
      System.Delete( LResponse, 1, Pos('{', LResponse) -1 );
      LResponse := Copy(LResponse, 1, pos(';</', LResponse )-1 );

      LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
      try
        if LJSONData <> nil then begin
          Lconfig := TJSONObject(LJSONData).Get('config').JsonValue;
          if LConfig <> nil then begin
            Lcsrf_token := TJSONObject(Lconfig).Get('csrf_token').JsonValue;
            if Lcsrf_token <> nil
              then FInstaInfo.csrf_token := Lcsrf_token.Value;
          end;
        end;
      finally
        LJSONData.Free;
      end;

      LClient.CustHeaders.Clear;
        LClient.CustomHeaders['x-requested-with'] := 'XMLHttpRequest';
        LClient.CustomHeaders['referer']          := LLogin;
        LClient.CustomHeaders['x-csrftoken']      := FInstaInfo.csrf_token;

      LPostData := TStringList.Create;
      try
        LPostData.Values['username']      := FInstaInfo.username;
        LPostData.Values['enc_password']  := Format('#PWD_INSTAGRAM_BROWSER:0:%s:%s', [ FInstaInfo.timestamp, FInstaInfo.password ]);
        LPostData.Values['queryParams']   := '{}';
        LPostData.Values['optIntoOneTap'] := 'false';

        LResponse := LClient.Post( LLoginAjax, LPostData ).ContentAsString;

        LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
        try
          if LJSONData <> nil then begin
            Form1.Memo1.Lines.Add( LJSONData.Format );
            FInstaInfo.status         := TJSONObject(LJSONData).Get('status').JsonValue.Value;
            if FInstaInfo.status = 'ok' then begin
              FInstaInfo.user           := TJSONObject(LJSONData).Get('user').JsonValue.Value;
              FInstaInfo.authenticated  := TJSONObject(LJSONData).Get('authenticated').JsonValue.Value;

            //if TJSONObject(LJSONData).FindValue('userId') <> nil
            //  then FInstaInfo.userId         := TJSONObject(LJSONData).Get('userId').JsonValue.Value;
            //if TJSONObject(LJSONData).FindValue('oneTapPrompt') <> nil
            //  then FInstaInfo.oneTapPrompt   := TJSONObject(LJSONData).Get('oneTapPrompt').JsonValue.Value;

              LDummyValue := nil;
              TJSONObject(LJSONData).TryGetValue( 'userId', LDummyValue );
                if LDummyValue <> nil then FInstaInfo.userId := LDummyValue.Value;
              LDummyValue := nil;
              TJSONObject(LJSONData).TryGetValue( 'oneTapPrompt', LDummyValue );
                if LDummyValue <> nil then FInstaInfo.oneTapPrompt := LDummyValue.Value;

            end else begin
            //if TJSONObject(LJSONData).FindValue('message') <> nil
            //  then FInstaInfo.message_     := TJSONObject(LJSONData).Get('message').JsonValue.Value;

              LDummyValue := nil;
              TJSONObject(LJSONData).TryGetValue( 'message', LDummyValue );
                if LDummyValue <> nil then FInstaInfo.message_ := LDummyValue.Value;
            end;
          end;
        finally
          LJSONData.Free;
        end;
      finally
        FreeAndNil( LPostData );
      end;
    end;
  finally
    FreeAndNil( LClient );
  end;
end;


Saygılarımla
Muharrem ARMAN

guplouajuixjzfm15eqb.gif
Cevapla
#6
(19-05-2021, Saat: 12:52)mrmarman Adlı Kullanıcıdan Alıntı: Eski sürüm Delphi olmalı.

* Kontroller önemli iki ihtimalli sonuç dönüyor çünkü...

Aşağıdaki şekilde deneyin. Bu defa önce ara demiyoruz TryGetValue şeklinde almaya çalışıp alınabildiyse sonucu yönlendiriyoruz.
* Güncelleme anlaşılsın diye orjinal hallerine // ile comment tagına alıp altlarına uyumlusunu yazdım.



procedure LoginInstagram();
const
  LLogin          = 'https://www.instagram.com/accounts/login/';
  LLoginAjax      = 'https://www.instagram.com/accounts/login/ajax/';
  LUserAgent      = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36';
var
  LClient     : System.Net.HttpClientComponent.TNetHTTPClient;
  LResponse   : String;
  LJSONData   : TJSONValue;
  Lconfig     : TJSONValue;
  Lcsrf_token : TJSONValue;
  LPostData   : TStringList;
  LDummyValue : TJSONValue;
begin
  FInstaInfo.timestamp  := IntToStr( DateTimeToUnix( Now() ) );
  LClient := TNetHTTPClient.Create(nil);
  try
    LClient.UserAgent  := LUserAgent;
    LResponse := LClient.Get( LLogin ).ContentAsString;
    if Pos('window._sharedData', LResponse) > 0 then
    begin
      System.Delete( LResponse, 1, Pos('window._sharedData', LResponse) );
      System.Delete( LResponse, 1, Pos('{', LResponse) -1 );
      LResponse := Copy(LResponse, 1, pos(';</', LResponse )-1 );

      LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
      try
        if LJSONData <> nil then begin
          Lconfig := TJSONObject(LJSONData).Get('config').JsonValue;
          if LConfig <> nil then begin
            Lcsrf_token := TJSONObject(Lconfig).Get('csrf_token').JsonValue;
            if Lcsrf_token <> nil
              then FInstaInfo.csrf_token := Lcsrf_token.Value;
          end;
        end;
      finally
        LJSONData.Free;
      end;

      LClient.CustHeaders.Clear;
        LClient.CustomHeaders['x-requested-with'] := 'XMLHttpRequest';
        LClient.CustomHeaders['referer']          := LLogin;
        LClient.CustomHeaders['x-csrftoken']      := FInstaInfo.csrf_token;

      LPostData := TStringList.Create;
      try
        LPostData.Values['username']      := FInstaInfo.username;
        LPostData.Values['enc_password']  := Format('#PWD_INSTAGRAM_BROWSER:0:%s:%s', [ FInstaInfo.timestamp, FInstaInfo.password ]);
        LPostData.Values['queryParams']   := '{}';
        LPostData.Values['optIntoOneTap'] := 'false';

        LResponse := LClient.Post( LLoginAjax, LPostData ).ContentAsString;

        LJSONData := TJSONObject.ParseJSONValue( System.SysUtils.TEncoding.ASCII.GetBytes( LResponse ), 0);
        try
          if LJSONData <> nil then begin
            Form1.Memo1.Lines.Add( LJSONData.Format );
            FInstaInfo.status         := TJSONObject(LJSONData).Get('status').JsonValue.Value;
            if FInstaInfo.status = 'ok' then begin
              FInstaInfo.user           := TJSONObject(LJSONData).Get('user').JsonValue.Value;
              FInstaInfo.authenticated  := TJSONObject(LJSONData).Get('authenticated').JsonValue.Value;

            //if TJSONObject(LJSONData).FindValue('userId') <> nil
            //  then FInstaInfo.userId         := TJSONObject(LJSONData).Get('userId').JsonValue.Value;
            //if TJSONObject(LJSONData).FindValue('oneTapPrompt') <> nil
            //  then FInstaInfo.oneTapPrompt   := TJSONObject(LJSONData).Get('oneTapPrompt').JsonValue.Value;

              LDummyValue := nil;
              TJSONObject(LJSONData).TryGetValue( 'userId', LDummyValue );
                if LDummyValue <> nil then FInstaInfo.userId := LDummyValue.Value;
              LDummyValue := nil;
              TJSONObject(LJSONData).TryGetValue( 'oneTapPrompt', LDummyValue );
                if LDummyValue <> nil then FInstaInfo.oneTapPrompt := LDummyValue.Value;

            end else begin
            //if TJSONObject(LJSONData).FindValue('message') <> nil
            //  then FInstaInfo.message_     := TJSONObject(LJSONData).Get('message').JsonValue.Value;

              LDummyValue := nil;
              TJSONObject(LJSONData).TryGetValue( 'message', LDummyValue );
                if LDummyValue <> nil then FInstaInfo.message_ := LDummyValue.Value;
            end;
          end;
        finally
          LJSONData.Free;
        end;
      finally
        FreeAndNil( LPostData );
      end;
    end;
  finally
    FreeAndNil( LClient );
  end;
end;



Muharrem Hocam evet Delphi xe10 sürümü biraz eski kaldı 10.4'ü yüklemiştim ama harici componentler'de çok sorun yaşadım. O nedenle xe 10'a döndüm. Yeni kodlarla çalıştı. Diğer aşamalara geçiyorum. Çok teşekkür ederim.
Cevapla
#7
çok güzel bir payllaşım olmuş instagram için önemli bir konuya değinilmiş
.
Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Delphi Editor ile hızalama enes_29 5 253 14-09-2022, Saat: 10:32
Son Yorum: frmman
  Delphi 'de exe içinde ki database ip tespit etme delphiX14 6 448 29-08-2022, Saat: 13:09
Son Yorum: tuna
  Delphi ile paintdeki renkle doldur özelliğinin yapılması JavaCiva 0 152 05-08-2022, Saat: 12:36
Son Yorum: JavaCiva
Photo Delphi-MySQL hata adnansirca 3 286 04-08-2022, Saat: 12:08
Son Yorum: adnansirca
  Delphi Proje Açarken Problem w0fly 3 355 03-08-2022, Saat: 17:42
Son Yorum: mcuyan



Konuyu Okuyanlar: 1 Ziyaretçi