コード例 #1
0
        private DTO.InstagramResult DoMediaSearch()
        {
            // get the list of media items
            // parse out the reponse and the fields we want
            // convert to DTOs and return

            string mediaFields    = "media%7Bmedia_url%2Cmedia_type%2Ccomments_count%2Clike_count%2Ctimestamp%2Cpermalink%2Ccaption%7D";
            string mediaSearchUrl = this.baseUrl + mediaFields + "&access_token=" + _token;

            List <InstagramResult> list = new List <InstagramResult>();

            //invoke the request
            string jsonResult = this.Get(mediaSearchUrl);

            // convert to json annotated object
            InstagramResult instagramResult = new InstagramResult();

            instagramResult = JsonConvert.DeserializeObject <InstagramResult>(jsonResult);

            if (instagramResult != null && instagramResult.media != null)
            {
                return(instagramResult);
            }

            return(null);
        }
コード例 #2
0
        public async Task <List <Entity.Media> > GetMediaAsync()
        {
            // invoke the private method - DoMediaSearch()
            InstagramResult     instagramResults = this.DoMediaSearch();
            List <Entity.Media> mediaModels      = new List <Entity.Media>();

            //map from the JSON/DTO returned by DoMediaSearch() to the Domain Entities
            foreach (MediaData mediaData in instagramResults.media.data)
            {
                Entity.Media media = new Entity.Media
                {
                    id               = mediaData.id,
                    like_count       = mediaData.like_count,
                    caption          = mediaData.caption,
                    comments_count   = mediaData.comments_count,
                    impression_count = GetMediaImpressionValue(GetMediaImpressionsInsight(mediaData)),
                    media_url        = mediaData.media_url,
                    permalink        = mediaData.permalink,
                    timestamp        = mediaData.timestamp,
                    DateCreated      = mediaData.DateCreated
                };

                // run text analytics over the captionfield
                media.CaptionInsights = GetTextAnalyticsInsight(media.id, media.caption);

                // get comments and associated AI insights
                media.Comments = GetMediaCommentsEntities(mediaData);
                foreach (Comment comment in media.Comments)
                {
                    // run text analytics over text comments
                    comment.TextAnalyticsInsight = GetTextAnalyticsInsight(comment.id, comment.text);
                }

                // get image insights
                media.VisionInsights = await GetComputerVisionInsightAsync(media.media_url);

                // finally, add the fully hydrated object to our list and return it
                mediaModels.Add(media);
            }

            return(mediaModels);
        }