Exemplo n.º 1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var pinRequest = request as PinterestRequestMessage;
            var query      = HttpUtility.ParseQueryString(request.RequestUri.Query);
            var queryNew   = new HttpUtility.HttpQSCollection();

            queryNew["client_id"] = PinterestConstants.CLIENT_ID;
            queryNew["timestamp"] = PinterestHelpers.GenerateTimestamp();
            if (pinRequest.IsSigned)
            {
                var dataContent = new NameValueCollection();
                dataContent.Add(queryNew);
                dataContent.Add(query);
                if (request.Content != null)
                {
                    var postContent = HttpUtility.ParseQueryString(await request.Content.ReadAsStringAsync());
                    dataContent.Add(postContent);
                }
                var sortedContent = new HttpUtility.HttpQSCollection();
                foreach (var item in dataContent.AllKeys.OrderBy(k => k))
                {
                    sortedContent.Add(item, dataContent[item]);
                }
                queryNew["oauth_signature"] = PinterestHelpers.GenerateSignature(
                    request.Method.ToString(),
                    request.RequestUri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Path, UriFormat.UriEscaped),
                    sortedContent.ToString());
            }
            queryNew.Add(query);
            var uriBuilder = new UriBuilder(request.RequestUri);

            uriBuilder.Query   = queryNew.ToString();
            request.RequestUri = uriBuilder.Uri;
            return(await base.SendAsync(request, cancellationToken));
        }
Exemplo n.º 2
0
        public PinterestAPI()
        {
            _httpClientHandler = new PinterestHttpHandler()
            {
                CookieContainer        = new CookieContainer(),
                AutomaticDecompression = DecompressionMethods.GZip
            };

            _httpClient = new HttpClient(_httpClientHandler)
            {
                BaseAddress = new Uri("https://api.pinterest.com/v3/")
            };

            _httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
            _httpClient.DefaultRequestHeaders.Add("Accept-Language", "en_US");
            _httpClient.DefaultRequestHeaders.Add("User-Agent", PinterestConstants.USER_AGENT);

            _httpClient.DefaultRequestHeaders.Add("Pinterest-App-Info", "version=6.17.0;build=617040;environment=Release");
            _httpClient.DefaultRequestHeaders.Add("X-Pinterest-AppState", "active");
            _httpClient.DefaultRequestHeaders.Add("X-Pinterest-App-Type", "3");
            _httpClient.DefaultRequestHeaders.Add("X-Pinterest-Device", "SCH-I829");
            _httpClient.DefaultRequestHeaders.Add("X-Pinterest-Device-HardwareId", "a7919442c027368");
            _httpClient.DefaultRequestHeaders.Add("X-Pinterest-InstallId", PinterestHelpers.GenerateInstallId());

            _httpClient.DefaultRequestHeaders.Add("Connection", "keep-alive");
            _httpClient.DefaultRequestHeaders.Add("Host", "api.pinterest.com");
        }