public IResult <EdgeHashtagToMedia> GetHashtagMedias(string hashtag, string endCursor, int limitPerPage = 12) { try { var uri = string.Format(InstagramGraphApiConstants.EXPLORE_TAG_DATA, hashtag, limitPerPage, endCursor); var variables = string.Format("{0}:{{\"tag_name\":\"{1}\",\"show_ranked\":false,\"first\":{2},\"after\":\"{3}\"}}", _user.UserRhxGis, hashtag, limitPerPage, endCursor); var signature = ApplicationHelper.CreateMD5(variables); var request = HttpHelper.GetDefaultRequest(uri); request.Headers["X-Instagram-GIS"] = signature; request.Headers["Cookie"] = _user.UserCookie; var response = HttpHelper.GetDefaultResponse(request); var json = response.ReadAsString(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <EdgeHashtagToMedia>(response, json)); } var objRetorno = JsonConvert.DeserializeObject <HashtagMedias>(json); EdgeHashtagToMedia EdgeHashtagToMedia = GetEdgeHashtagToMedia(objRetorno.Data.Hashtag); return(Result.Success(EdgeHashtagToMedia)); } catch (Exception ex) { return(Result.Fail <EdgeHashtagToMedia>(ex.Message)); } }
private EdgeHashtagToMedia GetEdgeHashtagToMedia(Hashtag Hashtag) { EdgeHashtagToMedia EdgeHashtagToMedia = new EdgeHashtagToMedia(); EdgeHashtagToMedia.PageInfo = Hashtag.EdgeHashtagToMedia.PageInfo; EdgeHashtagToMedia.Edges = new List <EdgeHashtagToMediaEdges>(); if (Hashtag.EdgeHashtagToMedia == null) { return(null); } var medias = Hashtag.EdgeHashtagToMedia; var ImageMedias = medias.Edges.Where(c => c.Node.Typename == MediaType.Image).ToList(); var SidecarMedias = medias.Edges.Where(c => c.Node.Typename == MediaType.Sidecar).ToList(); var VideosMedias = medias.Edges.Where(c => c.Node.Typename == MediaType.Video).ToList(); foreach (var image in ImageMedias) { EdgeHashtagToMedia.Edges.Add(new EdgeHashtagToMediaEdges() { Node = image.Node }); } foreach (var sidecar in SidecarMedias) { var shortcode = sidecar.Node.Shortcode; var sidecarShortcodeData = GetShortcodeHashtagMedia(shortcode); EdgeHashtagToMedia.Edges.Add(new EdgeHashtagToMediaEdges() { ShortcodeNode = sidecarShortcodeData.Data.ShortcodeMediaHashtag }); } foreach (var video in VideosMedias) { var shortcode = video.Node.Shortcode; var videoShortcodeData = GetShortcodeHashtagMedia(shortcode); EdgeHashtagToMedia.Edges.Add(new EdgeHashtagToMediaEdges() { ShortcodeNode = videoShortcodeData.Data.ShortcodeMediaHashtag }); } return(EdgeHashtagToMedia); }