/// <inheritdoc />
        public async Task <IList <Post> > GetPostsAsync(string pageId)
        {
            var token = await BootStrap();;
            var list  = new List <Facebook.Post>();
            var url   = $"{BASE_URL}/{VERSION}/{pageId}";

            url = QueryHelpers.AddQueryString(url, "access_token", token);
            url = QueryHelpers.AddQueryString(url, "fields", "posts{attachments,id,created_time,message,story}");

            do
            {
                var resp = await _client.GetAsync <Facebook.FacebookPostsResponse>(url);

                list.AddRange(resp?.Posts?.Data ?? new List <Facebook.Post>(0));

                url = resp?.Posts?.Paging?.Next;
            } while (!string.IsNullOrWhiteSpace(url));

            return(list.Select(item => new Post
            {
                Id = item?.Id,
                PublishedDate = item?.CreatedTime ?? DateTime.MinValue,
                Title = item?.Story
            }).ToList());
        }
        /// <inheritdoc />
        public async Task <string> GetChannelIdAsync(string channelName)
        {
            var url = BASE_URL + "channels";

            url = QueryHelpers.AddQueryString(url, "part", "id");
            url = QueryHelpers.AddQueryString(url, "forUsername", channelName);
            url = QueryHelpers.AddQueryString(url, "key", _apiKey);
            url = QueryHelpers.AddQueryString(url, "maxResults", "1");
            url = QueryHelpers.AddQueryString(url, "fields", "items/id,nextPageToken");

            var parsedResp = await _client.GetAsync <YouTube.OnlyIdResponse>(url);

            return(parsedResp?.Items?.FirstOrDefault()?.Id);
        }
        /// <inheritdoc />
        public async Task <string> GetPersonIdAsync(string name)
        {
            var url       = BASE_URL + "people";
            var pageToken = string.Empty;

            url = QueryHelpers.AddQueryString(url, "query", $"\"{name}\"");
            url = QueryHelpers.AddQueryString(url, "key", _apiKey);
            url = QueryHelpers.AddQueryString(url, "maxResults", "50");
            url = QueryHelpers.AddQueryString(url, "fields", "items(displayName,id),nextPageToken");

            do
            {
                var pageUrl    = string.IsNullOrWhiteSpace(pageToken) ? url : QueryHelpers.AddQueryString(url, "pageToken", pageToken);
                var parsedResp = await _client.GetAsync <GooglePlus.PeopleResponse>(pageUrl);

                var foundItem = parsedResp?.Items?.FirstOrDefault(item => item?.DisplayName?.Equals(name, StringComparison.OrdinalIgnoreCase) ?? false);
                if (foundItem != null)
                {
                    return(foundItem.Id);
                }
                pageToken = parsedResp?.NextPageToken;
            } while (!string.IsNullOrWhiteSpace(pageToken));
            return(null);
        }
Ejemplo n.º 4
0
        public static async Task <T> Get <T>(ISafeHttpClient client, string getUri)
        {
            var response = await client.GetAsync(getUri);

            return(JsonConvert.DeserializeObject <T>(await response.Content.ReadAsStringAsync()));
        }