Skip to content

Instantly share code, notes, and snippets.

@Al-Muhandis
Last active November 2, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Al-Muhandis/b2bc7550413437442cd1d4911f818cea to your computer and use it in GitHub Desktop.
Save Al-Muhandis/b2bc7550413437442cd1d4911f818cea to your computer and use it in GitHub Desktop.
The piece of code for parsing timeless stories to my instagram [FreePascal language]
const
QryHash_HLStoriesIDs = '7c16654f22c819fb63d1183034a5162f';
QryHash_HLStories1 = '45246d3fe16ccc6577e0bd297a5db1ab';
{ ... ... ... }
function TInstagramParser.getHLStoriesForUser_internal(AUserID: Int64): Tjson_HLStories;
var
variables: TJSONObject;
HLIds, HL_reels: TJSONArray;
edge: TJSONEnum;
begin
Result:=nil;
variables:=TJSONObject.Create(['user_id', AUserID, 'include_chaining', False,
'include_reel', True, 'include_suggested_users', False, 'include_logged_out_extras', False,
'include_highlight_reels', True]);
HL_reels:=getEdgesFromGraphQueryHash(QryHash_HLStoriesIDs, variables,
'data.user.edge_highlight_reels.edges');
variables.Free;
if Assigned(HL_reels) then
begin
try
HLIds:=TJSONArray.Create;
for edge in HL_reels do
HLIds.Add((edge.Value as TJSONObject).Objects['node'].Int64s['id']);
variables:=TJSONObject.Create(['reel_ids', TJSONArray.Create,
'tag_names', TJSONArray.Create, 'location_ids', TJSONArray.Create,
'highlight_reel_ids', HLIds, 'precomposed_overlay', False]);
Result:=getEdgesFromGraphQueryHash(QryHash_HLStories1, variables, 'data.reels_media');
variables.Free;
finally
HL_reels.Free;
end;
end;
end;
{ ... ... ...}
function TInstagramParser.getEdgesFromGraphQueryHash(const AHash: String;
variables: TJSONObject; const ResPath: String): TJSONArray;
var
jsonResponse: TJSONObject;
jsonArray: TJSONArray;
u: String;
begin
Result:=nil;
try
variables.CompressedJSON:=True;
generateHeaders(UserSession);
u:=getGraphQlQueryHashUrl(AHash, variables.AsJSON);
jsonResponse:=HTTPGetJSON(u);
if not Assigned(jsonResponse) then
Exit;
try
{$IFDEF DEBUG} StrToFile(jsonResponse.AsJSON, '~queryhash.json'); {$ENDIF}
jsonArray:=jsonResponse.FindPath(ResPath) as TJSONArray;
if Assigned(jsonArray) then
Result:=jsonArray.Clone as TJSONArray;
finally
jsonResponse.Free;
end;
except
Result:=nil;
end;
end;
{ ... ... ... }
class function TInstagramParser.getGraphQlQueryHashUrl(const QueryHash: String;
const Parameters: String): String;
begin
Result := ReplaceStr(GRAPH_QL_QUERY_URL1, '{{queryHash}}', QueryHash);
if Parameters<>EmptyStr then
Result+='&' + 'variables='+EncodeURLElement(Parameters);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment