66'
77' This program is distributed in the hope that it will be useful,
88' but WITHOUT ANY WARRANTY
9+ Imports System.Security.Cryptography
910Imports System.Threading
10- Imports SCrawler.API.Base
11- Imports PersonalUtilities.Functions.XML
1211Imports PersonalUtilities.Functions.RegularExpressions
12+ Imports PersonalUtilities.Functions.XML
1313Imports PersonalUtilities.Tools.Web.Clients
1414Imports PersonalUtilities.Tools.Web.Documents.JSON
15+ Imports SCrawler.API.Base
1516Namespace API.Instagram
1617 Partial Friend Class UserData
1718# Region "Tokens"
@@ -43,9 +44,9 @@ Namespace API.Instagram
4344 Private Const GQL_UserStories_DocId As String = "25231722019806941"
4445 Private Const GQL_UserStories_FbFriendlyName As String = "PolarisStoriesV3ReelPageStandaloneQuery"
4546
46- Private Const GQL_Timeline_DocId As String = "7268577773270422"
47+ Private Const GQL_Timeline_DocId As String = "7268577773270422" '"34579740524958711" '"7268577773270422"
4748 Private Const GQL_Timeline_FbFriendlyName As String = "PolarisProfilePostsQuery"
48- Private Const GQL_Timeline_DocId_Second As String = "7286316061475375"
49+ Private Const GQL_Timeline_DocId_Second As String = "7286316061475375" '"33944389991841132" '"7286316061475375"
4950 Private Const GQL_Timeline_FbFriendlyName_Second As String = "PolarisProfilePostsTabContentQuery_connection"
5051
5152 Private Const GQL_Reels_DocId As String = "7191572580905225"
@@ -64,48 +65,61 @@ Namespace API.Instagram
6465 Responser.Headers.Add(GQL_HEADER_FB_FRINDLY_NAME, HeaderValue)
6566 Responser.Headers.Add(GQL_HEADER_FB_LSD, Token_lsd)
6667 End Sub
67- <Obsolete( "Use 'GET' function: 'GetUserData'" , False )>
68- Private Sub GetUserDataGQL( ByVal Token As CancellationToken)
68+ ' <Obsolete("Use 'GET' function: 'GetUserData'", False)>
69+ Private Function GetUserDataGQL( ByVal Token As CancellationToken) As String
6970 Dim vars$ = String .Format(GQL_URL_PATTERN_VARS, GQL_UserData_DocId, Token_lsd, Token_dtsg_Var, GQL_UserData_FbFriendlyName,
7071 SymbolsConverter.ASCII.EncodeSymbolsOnly( "{" & $"""id"":""{ID}"",""relay_header"":false,""render_surface"":""PROFILE""" & "}" ))
7172 UpdateRequestNumber()
7273 ChangeResponserMode( True )
7374 UpdateHeadersGQL(GQL_UserData_FbFriendlyName)
7475 Dim r$ = Responser.GetResponse(GQL_URL, vars)
75- If Not r.IsEmptyString Then
76- Using j As EContainer = JsonDocument.Parse(r)
77- If j.ListExists Then
78- With j({ "data" , "user" })
79- If .ListExists Then
80- UserSiteName = .Value( "full_name" ).IfNullOrEmpty(UserSiteName)
81- Dim f As New SFile With {.Path = DownloadContentDefault_GetRootDir(), .Name = "ProfilePicture" , .Extension = "jpg" }
82- Dim pic$ = .Value({ "hd_profile_pic_url_info" }, "url" ).IfNullOrEmpty(.Value( "profile_pic_url" ))
83- If Not pic.IsEmptyString Then GetWebFile(pic, f, EDP.ReturnValue)
84- UserDescriptionUpdate(.Value( "biography" ))
85- End If
86- End With
87- End If
88- End Using
89- End If
90- End Sub
76+ Return r
77+ 'If Not r.IsEmptyString Then
78+ ' Using j As EContainer = JsonDocument.Parse(r)
79+ ' If j.ListExists Then
80+ ' With j({"data", "user"})
81+ ' If .ListExists Then
82+ ' UserSiteName = .Value("full_name").IfNullOrEmpty(UserSiteName)
83+ ' IsVerifiedProfile = .Value("is_verified").FromXML(Of Boolean)(False)
84+ ' IsVerifiedProfile_Checked = True
85+ ' Dim descr$ = .Value("biography")
86+ ' If If(.Item("bio_links")?.Count, 0) > 0 Then descr.StringAppend(.Item("bio_links").Select(Function(bl) bl.Value("url")).ListToString(vbNewLine), vbNewLine)
87+ ' Dim eUrl$ = .Value("external_url")
88+ ' If Not eUrl.IsEmptyString AndAlso (descr.IsEmptyString OrElse Not descr.Contains(eUrl)) Then descr.StringAppendLine(eUrl)
89+ ' UserDescriptionUpdate(descr)
90+
91+ ' Dim f As New SFile With {.Path = DownloadContentDefault_GetRootDir(), .Name = "ProfilePicture", .Extension = "jpg"}
92+ ' Dim pic$ = .Value({"hd_profile_pic_url_info"}, "url").IfNullOrEmpty(.Value("profile_pic_url"))
93+ ' If Not pic.IsEmptyString Then GetWebFile(pic, f, EDP.ReturnValue)
94+ ' End If
95+ ' End With
96+ ' End If
97+ ' End Using
98+ 'End If
99+ End Function
91100 Private Function GetTimelineGQL( ByVal Cursor As String , ByVal Token As CancellationToken) As String
92101 Const none_cursor$ = "none"
93- Dim nextCursor$ = String .Empty, hasNextPage$ = String .Empty
102+ Dim nextCursor$ = String .Empty
103+ Dim hasNextPage As Boolean = False
94104 Dim vars$
95105
96106 ThrowAny(Token)
97107 UpdateRequestNumber()
98108 ChangeResponserMode( True )
99109
100110 If Cursor.IsEmptyString Then
101- vars = "{""data"":{""count"":50 ,""include_relationship_info"":true,""latest_besties_reel_media"":true,""latest_reel_media"":true},""username"":""" &
111+ vars = "{""data"":{""count"":" & PostNumberPerRequest & " ,""include_relationship_info"":true,""latest_besties_reel_media"":true,""latest_reel_media"":true},""username"":""" &
102112 NameTrue & """,""__relay_internal__pv__PolarisShareMenurelayprovider"":false}"
113+ 'vars = "{""data"":{""count"":" & PostNumberPerRequest & ",""include_reel_media_seen_timestamp"":true,""include_relationship_info"":true,""latest_besties_reel_media"":true,""latest_reel_media"":true},""username"":""" &
114+ ' NameTrue & """,""__relay_internal__pv__PolarisShareMenurelayprovider"":false}"
103115 vars = String .Format(GQL_URL_PATTERN_VARS, GQL_Timeline_DocId, Token_lsd, Token_dtsg_Var, GQL_Timeline_FbFriendlyName,
104116 SymbolsConverter.ASCII.EncodeSymbolsOnly(vars))
105117 UpdateHeadersGQL(GQL_Timeline_FbFriendlyName)
106118 Else
107- vars = "{""after"":""" & Cursor & """,""before"":null,""data"":{""count"":50 ,""include_relationship_info"":true,""latest_besties_reel_media"":true,""latest_reel_media"":true},""first"":50 ,""last"":null,""username"":""" &
119+ vars = "{""after"":""" & Cursor & """,""before"":null,""data"":{""count"":" & PostNumberPerRequest & " ,""include_relationship_info"":true,""latest_besties_reel_media"":true,""latest_reel_media"":true},""first"":" & PostNumberPerRequest & " ,""last"":null,""username"":""" &
108120 NameTrue & """,""__relay_internal__pv__PolarisShareMenurelayprovider"":false}"
121+ 'vars = "{""after"":""" & Cursor & """,""before"":null,""data"":{""count"":" & PostNumberPerRequest & ",""include_reel_media_seen_timestamp"":true,""include_relationship_info"":true,""latest_besties_reel_media"":true,""latest_reel_media"":true},""first"":" & PostNumberPerRequest & ",""last"":null,""username"":""" &
122+ ' NameTrue & """}"
109123 vars = String .Format(GQL_URL_PATTERN_VARS, GQL_Timeline_DocId_Second, Token_lsd, Token_dtsg_Var, GQL_Timeline_FbFriendlyName_Second,
110124 SymbolsConverter.ASCII.EncodeSymbolsOnly(vars))
111125 UpdateHeadersGQL(GQL_Timeline_FbFriendlyName_Second)
@@ -140,7 +154,8 @@ Namespace API.Instagram
140154 End Function
141155 Private Function GetHighlightsGQL_List() As List( Of String )
142156
143- Dim nextCursor$ = String .Empty, hasNextPage$ = String .Empty
157+ Dim nextCursor$ = String .Empty
158+ Dim hasNextPage As Boolean = False
144159 Dim i% = - 1
145160 Dim hList As New List( Of String )
146161 Dim tmpList As New List( Of String )
@@ -178,7 +193,9 @@ Namespace API.Instagram
178193 Dim tmpList As New List( Of String )
179194 Dim i% = - 1
180195 If StoriesList.ListExists Then
181- tmpList.AddRange(StoriesList.Take( 10 ))
196+ 'TODO: 5 Instagram stories
197+ 'tmpList.AddRange(StoriesList.Take(10))
198+ tmpList.AddRange(StoriesList.Take( 5 ))
182199 StoriesList.RemoveRange( 0 , tmpList.Count)
183200
184201 Dim vars$ = String .Format(GQL_URL_PATTERN_VARS, GQL_Highlights_DocId_Second, Token_lsd, Token_dtsg_Var, GQL_Highlights_FbFriendlyName_Second,
@@ -238,11 +255,9 @@ Namespace API.Instagram
238255 Private Function GetReelsGQL( ByVal Cursor As String ) As String
239256 GetReelsGQL_SetEnvir = True
240257
241- Dim errData$ = String .Empty
242- If Cursor.IsEmptyString And Not ValidateBaseTokens() Then GetPageTokens()
243- If Cursor.IsEmptyString And Not ValidateBaseTokens(errData) Then ValidateBaseTokens_Error(errData)
258+ UpdateTokens(Cursor.IsEmptyString)
244259
245- Dim vars$ = """data"":{""include_feed_video"":true,""page_size"":50 ,""target_user_id"":""" & ID & """}"
260+ Dim vars$ = """data"":{""include_feed_video"":true,""page_size"":" & PostNumberPerRequest & " ,""target_user_id"":""" & ID & """}"
246261 If Not Cursor.IsEmptyString Then vars = $"""after"":""{Cursor}"",""before"":null,{vars},""first"":4,""last"":null"
247262 vars = String .Format(GQL_URL_PATTERN_VARS, GQL_Reels_DocId, Token_lsd, Token_dtsg_Var, GQL_Reels_FbFriendlyName,
248263 SymbolsConverter.ASCII.EncodeSymbolsOnly( "{" & vars & "}" ))
@@ -258,10 +273,10 @@ Namespace API.Instagram
258273 Dim vars$
259274 If Cursor.IsEmptyString Then
260275 vars = String .Format(GQL_URL_PATTERN_VARS, GQL_Tagged_DocId, Token_lsd, Token_dtsg_Var, GQL_Tagged_FbFriendlyName,
261- SymbolsConverter.ASCII.EncodeSymbolsOnly( "{" & $"""count"":50 ,""user_id"":""{ID}""" & "}" ))
276+ SymbolsConverter.ASCII.EncodeSymbolsOnly( "{" & $"""count"":{PostNumberPerRequest} ,""user_id"":""{ID}""" & "}" ))
262277 Else
263278 vars = String .Format(GQL_URL_PATTERN_VARS, GQL_Tagged_DocId, Token_lsd, Token_dtsg_Var, GQL_Tagged_FbFriendlyName,
264- SymbolsConverter.ASCII.EncodeSymbolsOnly( "{" & $"""after"":""{Cursor}"",""before"":null,""count"":50 ,""first"":50 ,""last"":null,""user_id"":""{ID}""" & "}" ))
279+ SymbolsConverter.ASCII.EncodeSymbolsOnly( "{" & $"""after"":""{Cursor}"",""before"":null,""count"":{PostNumberPerRequest} ,""first"":{PostNumberPerRequest} ,""last"":null,""user_id"":""{ID}""" & "}" ))
265280 End If
266281 UpdateRequestNumber()
267282 ChangeResponserMode( True )
@@ -270,6 +285,13 @@ Namespace API.Instagram
270285 End Function
271286# End Region
272287# Region "ValidateBaseTokens"
288+ Private Sub UpdateTokens( ByVal process As Boolean )
289+ If process Then
290+ Dim TokensErrData$ = String .Empty
291+ If Not ValidateBaseTokens() Then GetPageTokens()
292+ If Not ValidateBaseTokens(TokensErrData) Then ValidateBaseTokens_Error(TokensErrData)
293+ End If
294+ End Sub
273295 Protected Overridable Overloads Function ValidateBaseTokens() As Boolean
274296 Return ValidateBaseTokens( Nothing )
275297 End Function
@@ -307,6 +329,10 @@ Namespace API.Instagram
307329 Try
308330 If Not r.IsEmptyString Then
309331 ResetBaseTokens()
332+ If ID.IsEmptyString Then
333+ Dim __id$ = RegexReplace(r, Regex_ProfileID)
334+ If CLng (AConvert( Of Long )(__id, 0 , EDP.ReturnValue)) <> 0 Then ID = __id
335+ End If
310336 Select Case Attempt
311337 Case 0
312338 Dim rr As RParams = RParams.DM(PageTokenRegexPatternDefault, 0 , RegexReturn.List, EDP.ReturnValue)
0 commit comments