Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PobierzTokenTwitch(login, haslo: string): string;
- var
- IdHTTP: TIdHTTP;
- IdSSL: TIdSSLIOHandlerSocketOpenSSL;
- HTML, authToken: string;
- parametry: TStringList;
- poczatek, koniec: integer;
- strumien: TMemoryStream;
- // stringDoWyslania: TStringStream;
- begin
- try
- IdHTTP := TIdHTTP.Create;
- parametry := TStringList.Create;
- strumien := TMemoryStream.Create;
- try
- IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
- IdHTTP.IOHandler := IdSSL;
- IdHTTP.AllowCookies := True;
- IdHTTP.CookieManager := Form1.IdCookieManager1;
- Form1.IdCookieManager1.CookieCollection.Clear;
- IdHTTP.HandleRedirects := True;
- HTML := IdHTTP.Get('http://www.twitch.tv/login');
- poczatek := Pos('"authenticity_token" type="hidden" value="', HTML) + Length('"authenticity_token" type="hidden" value="');
- koniec := PosEx('"', HTML, poczatek);
- authToken := copy(HTML, poczatek, koniec - poczatek);
- try
- parametry.Add('utf8=✓');
- parametry.Add('authenticity_token=' + authToken);
- parametry.Add('redirect_on_login=');
- parametry.Add('embed_form=false');
- parametry.Add('login=' + login);
- parametry.Add('password=' + haslo);
- // try
- IdHTTP.Post('https://secure.twitch.tv/user/login', parametry, strumien, IndyTextEncoding_UTF8());
- // except
- // end;
- Delay(1000);
- parametry.Clear;
- parametry.Add('utf8=✓');
- parametry.Add('authenticity_token=' + authToken);
- parametry.Add('login_type=login');
- parametry.Add('response_type=token');
- parametry.Add('client_id=smb61nyd0vxmqdn9d3k735qbx41cdyg');
- parametry.Add('redirect_uri=http://localhost');
- parametry.Add('scope=chat_login channel_editor channel_read');
- IdHTTP.Post('https://api.twitch.tv/kraken/oauth2/allow', parametry, strumien, IndyTextEncoding_UTF8());
- IdHTTP.Get('https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=smb61nyd0vxmqdn9d3k735qbx41cdyg' +
- '&redirect_uri=http://localhost&scope=chat_login+channel_editor+channel_read');
- finally
- poczatek := Pos('#access_token', IdHTTP.Response.Location);
- if poczatek > 0 then Result := 'oauth:' + copy(IdHTTP.Response.Location, poczatek + 14, 31);
- end;
- finally
- IdHTTP.Free;
- parametry.Free;
- strumien.Free;
- // IdSSLOpenSSL.UnLoadOpenSSLLibrary();
- end;
- except
- // on E: Exception do
- // ShowMessage(E.Message);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment