• R/O
  • SSH
  • HTTPS

facebooktools: Commit


Commit MetaInfo

Revision7 (tree)
Time2020-04-17 04:52:34
Authorderekwildstar

Log Message

Funcionalidade de compartilhamento concluída e testada

Change Summary

Incremental Difference

--- trunk/src/UDAMOPrincipal.pas (revision 6)
+++ trunk/src/UDAMOPrincipal.pas (revision 7)
@@ -25,7 +25,10 @@
2525 h: String;
2626 end;
2727
28+ TPublicationType = (ptUnknown, ptTextOnly, ptTextAndAttachment, ptTextAndLink);
29+
2830 TPublicationParameters = record
31+ PublicationType: TPublicationType;
2932 Message: String;
3033 IncludeOriginalPublication: Boolean;
3134 PublicationOwnerId: String;
@@ -58,7 +61,7 @@
5861 procedure ProgramToConfig;
5962 function GetGroupInfo(AGroupUrl: String; out AGroupInfo: TGroupInfo): Boolean;
6063 function ShareToGroup(AGroupInfo: TGroupInfo; APublicationParameters: TPublicationParameters): Boolean;
61- procedure Wait10Seconds;
64+ procedure Wait5Seconds;
6265 public
6366 { Public declarations }
6467 constructor Create(AOwner: TComponent); override;
@@ -86,7 +89,8 @@
8689 uses
8790 KRK.Rtl.Win.WinInet.Utilities, JSON, Windows, WinInet, Vcl.Forms,
8891 Vcl.Controls, UFormPrincipal, jpeg, MSHTML, RegularExpressionsCore,
89- KRK.RegExp.Utils, NetEncoding, Generics.Collections, UFORMBatchGroupSharingProgress;
92+ KRK.RegExp.Utils, NetEncoding, Generics.Collections, UFORMBatchGroupSharingProgress
93+ ,ActiveX;
9094
9195 // use este site para gerar classes proxy para seus JSON
9296 // https://jsontodelphi.com
@@ -123,6 +127,7 @@
123127 var
124128 RO: TRequestOptions;
125129 RE: TResponse;
130+ AI: String;
126131 begin
127132 Result := False;
128133 ZeroMemory(@RO,SizeOf(RO));
@@ -134,7 +139,13 @@
134139 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
135140 { InternetConnect }
136141 RO.InternetConnectParams.Service := INTERNET_SERVICE_HTTP;
137- RO.InternetConnectParams.ServerName := PChar('https://www.facebook.com/share/dialog/submit/?app_id=2309869772&audience_type=group&audience_targets[0]=' + AGroupInfo.id + '&is_forced_reshare_of_post=' + APublicationParameters.IncludeOriginalPublication.ToString(TUseBoolStrs(true)) + '&message=' + TNetEncoding.URL.Encode(APublicationParameters.Message) + '&owner_id=' + APublicationParameters.PublicationOwnerId + '&post_id=' + APublicationParameters.PublicationId + '&shared_from_post_id=' + APublicationParameters.PublicationId);
142+
143+ case APublicationParameters.PublicationType of
144+ ptTextOnly, ptTextAndAttachment: AI := '25554907596';
145+ ptTextAndLink: AI := '2309869772'
146+ end;
147+
148+ RO.InternetConnectParams.ServerName := PChar('https://www.facebook.com/share/dialog/submit/?app_id=' + AI + '&audience_type=group&audience_targets[0]=' + AGroupInfo.id + '&is_forced_reshare_of_post=' + APublicationParameters.IncludeOriginalPublication.ToString(TUseBoolStrs(true)) + '&message=' + TNetEncoding.URL.Encode(APublicationParameters.Message) + '&owner_id=' + APublicationParameters.PublicationOwnerId + '&post_id=' + APublicationParameters.PublicationId + '&shared_from_post_id=' + APublicationParameters.PublicationId);
138149 { HttpOpenRequest }
139150 RO.HttpOpenRequestParams.AcceptTypes := TStringList.Create;
140151 RO.HttpOpenRequestParams.AcceptTypes.Text := '*/*';
@@ -219,6 +230,14 @@
219230 begin
220231 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] := TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] + 'Done!';
221232
233+ case PP.PublicationType of
234+ ptTextOnly: TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('This is a text only publication (25554907596)');
235+ ptTextAndAttachment: TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('This is a text+attachment publication (25554907596)');
236+ ptTextAndLink: TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('This is a text+link publication (2309869772)');
237+ end;
238+ // 2392950137 foi aplicado a um video ao vivo! não sei se qualquer video anexado funciona do mesmo modo
239+
240+
222241 PP.Message := AMessage;
223242 PP.IncludeOriginalPublication := AIncludeOriginalPublication;
224243
@@ -231,7 +250,7 @@
231250 if not FirstIteration then
232251 begin
233252 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('Waiting 10 seconds...');
234- Wait10Seconds;
253+ Wait5Seconds;
235254 end;
236255
237256 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('Sharing to group "' + GR.Name + '"...');
@@ -239,7 +258,7 @@
239258 if ShareToGroup(GR.GroupInfo,PP) then
240259 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] := TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] + 'Successful!'
241260 else
242- TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] := TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] + 'Error :(';
261+ TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] := TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] + 'Failed :(';
243262
244263 FirstIteration := False;
245264 end;
@@ -248,17 +267,24 @@
248267 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('Batch competed!');
249268 end
250269 else
270+ begin
251271 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] := TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines[Pred(TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Count)] + 'Fail!';
272+ TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('Check your publication. At this time only the following publication types are supported:');
273+ TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('- Text only');
274+ TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('- Text and attached image');
275+ TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('- Text and external link');
276+ TFORMBatchGroupSharingProgress(FB.InternalFormInstance).MEMOLog.Lines.Add('Uploaded videos and live videos are not supported!');
277+ end;
252278 finally
253279 TFORMBatchGroupSharingProgress(FB.InternalFormInstance).PNBBClose.Enable;
254280 end;
255281 end;
256282
257-procedure TDAMOPrincipal.Wait10Seconds;
283+procedure TDAMOPrincipal.Wait5Seconds;
258284 var
259285 TimeOut: Cardinal;
260286 begin
261- TimeOut := GetTickCount + 10000;
287+ TimeOut := GetTickCount + 5000;
262288 while GetTickCount < TimeOut do;
263289 end;
264290
@@ -864,6 +890,18 @@
864890 try
865891 Request(RO, RE);
866892
893+// with TStringList.Create do
894+// try
895+// Add(TStringStream(RE.Content).DataString);
896+// // Add('===============================================');
897+// // Add(HD.all.item(1).innerHtml);
898+//
899+// SaveToFile('D:\pagina.html')
900+// finally
901+// Free;
902+// end;
903+
904+
867905 if RegExMatch(TStringStream(RE.Content).DataString
868906 ,'\{"imp_id":".*","ef_page":.*,"uri":".*","entity_id":".*"\}'
869907 ,0
@@ -901,16 +939,95 @@
901939 end;
902940
903941 var HD: OleVariant := coHTMLDocument.Create as IHTMLDocument2;
904- HD.Write(TStringStream(RE.Content).DataString);
942+ // Habilita o modo de design, o qual desabilita scripts e permite a
943+ // leitura do código da página exatamente como ele é. Scripts podem
944+ // modificar o DOM, logo, ao usar esta propriedade o texto parseado
945+ // pode ser diferente daquilo que ele seria ao não usar esta
946+ // propriedade. Ele está aqui porque eu percebi que o fonte como ele
947+ // vinha em RE.Content estava sendo modificado quando passava pelo
948+ // parser, então imaginei que era por conta de scripts estarem mudando
949+ // o DOM, porém testes posteriores mostraram que aquilo que os
950+ // navegadores mostram é exatamente aquilo que é retornado no parser,
951+ // sendo assim eu não precisei usar o designMode, porém o deixei aqui
952+ // comentado para lembrar de sua existência
953+ HD.designMode := 'On';
954+ HD.clear; //Não sei se isso é realmente necessário
955+ HD.write(TStringStream(RE.Content).DataString);
905956 HD.close;
906957
907- APublicationParameters.jazoest := HD.getElementsByName('jazoest').item[0].value;
908- APublicationParameters.fb_dtsg := HD.getElementsByName('fb_dtsg').item[0].value;
958+ var OneDiv: OleVariant;
959+ var OneDivAttributes: Olevariant;
909960
910- Result := (APublicationParameters.hsi <> '') and (APublicationParameters.pkg_cohort <> '') and
911- (APublicationParameters.client_revision <> '') and (APublicationParameters.__spin_b <> '') and
912- (APublicationParameters.__spin_r <> '') and (APublicationParameters.__spin_t <> '') and
913- (APublicationParameters.jazoest <> '') and (APublicationParameters.fb_dtsg <> '');
961+ // Obtém uma coleção de elementos div
962+ var DivCollection: OleVariant := HD.getElementsByTagName('div');
963+
964+ // Varre a coleção de elementos div buscando o primeiro que possua um
965+ // atributo data-testid com valor post_message
966+ for var i: Word := 0 to DivCollection.length - 1 do
967+ begin
968+ OneDiv := DivCollection.item(i);
969+ OneDivAttributes := OneDiv.attributes;
970+
971+ // Varre todos os atributos do div atual buscando um específico
972+ for var j: Byte := 0 to OneDivAttributes.length - 1 do
973+ begin
974+
975+ if (OneDivAttributes.item(j).name = 'data-testid') and (OneDivAttributes.item(j).value = 'post_message') then
976+ begin
977+ // Quando acha o atributo de mensagem da publicação, já
978+ // considera que é uma publicação somente texto.
979+ APublicationParameters.PublicationType := ptTextOnly;
980+
981+ // Verifica o próxmimo elemento (outro div) que pode ou não
982+ // conter algo
983+ if Pos('<a tabindex=-1',LowerCase(OneDiv.nextSibling.innerHtml)) <> 0 then
984+ APublicationParameters.PublicationType := ptTextAndLink
985+ else if Pos('<a',LowerCase(OneDiv.nextSibling.innerHtml)) <> 0 then
986+ APublicationParameters.PublicationType := ptTextAndAttachment;
987+
988+ Break;
989+ end;
990+ end;
991+
992+ // Se o atributo PublicationType tiver um valor diferente de
993+ // ptUnknown, então já achamos o que precisamos, então termina o
994+ // loop
995+ if APublicationParameters.PublicationType <> ptUnknown then
996+ Break;
997+ end;
998+
999+ // Apenas se detectamos o tipo da publicação é que podemos continuar
1000+ if APublicationParameters.PublicationType <> ptUnknown then
1001+ begin
1002+ // Quando não somos donos da publicação os inputs jazoest e fb_dtsg
1003+ // estão descomentados e podem ser acessados diretamente. Quando somos
1004+ // donos da publicação eles estão em um bloco de html comentado
1005+ if HD.getElementsByName('jazoest').length = 0 then
1006+ begin
1007+ var CodeCollection: OleVariant := HD.getElementsByTagName('code');
1008+
1009+ for var i: Word := 0 to CodeCollection.length - 1 do
1010+ begin
1011+ if Pos('name="jazoest"',LowerCase(CodeCollection.item(i).innerHtml)) <> 0 then
1012+ begin
1013+ HD.Clear;
1014+ HD.Write(CodeCollection.item(i).children[0].nodeValue);
1015+ HD.close;
1016+ Break;
1017+ end;
1018+ end;
1019+ end;
1020+
1021+
1022+ APublicationParameters.jazoest := HD.getElementsByName('jazoest').item[0].value;
1023+ APublicationParameters.fb_dtsg := HD.getElementsByName('fb_dtsg').item[0].value;
1024+
1025+ Result := (APublicationParameters.hsi <> '') and (APublicationParameters.pkg_cohort <> '') and
1026+ (APublicationParameters.client_revision <> '') and (APublicationParameters.__spin_b <> '') and
1027+ (APublicationParameters.__spin_r <> '') and (APublicationParameters.__spin_t <> '') and
1028+ (APublicationParameters.jazoest <> '') and (APublicationParameters.fb_dtsg <> '') and
1029+ (APublicationParameters.PublicationType <> ptUnknown);
1030+ end;
9141031 end;
9151032 end
9161033 else
Show on old repository browser