예제 #1
0
        public void GetProductsWithQueryStringRelative()
        {
            var serializer = new XmlSerializer(typeof(Crawler.Model.LinkShare.result));

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://feed.linksynergy.com");

            HttpQueryString query = new HttpQueryString();

            query.Add("token", "5bfb339580a02308573204c2ac1bb921ecba09ba542a19d271c2d7e9c27a509f");
            query.Add("keyword", "DVD Player");
            query.Add("Page", "1");
            query.Add("MaxResults", "100");


            var uri = HttpQueryString.MakeQueryString(new Uri("/productsearch?", UriKind.Relative), query);
            var req = new HttpRequestMessage("GET", uri);

            using (var response = client.Send(req))
            {
                //string results = response.Content.ReadAsString();
                var extended = (object)serializer.Deserialize(response.Content.ReadAsStream());
            }
        }
        /// <summary>
        /// Generates the authorization URL using the specified <paramref name="state"/> and <paramref name="scope"/>.
        /// </summary>
        /// <param name="state">The state to send to Vimeo's OAuth login page.</param>
        /// <param name="scope">The scope of the application.</param>
        /// <returns>An authorization URL based on <see cref="ClientId"/>, <see cref="RedirectUri"/>,
        /// <paramref name="state"/> and <paramref name="scope"/>.</returns>
        public string GetAuthorizationUrl(string state, string scope = null)
        {
            // Validate the input
            if (string.IsNullOrWhiteSpace(state))
            {
                throw new ArgumentNullException(nameof(state));
            }
            if (string.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (string.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }

            // Construct the query string
            IHttpQueryString query = new HttpQueryString();

            query.Add("response_type", "code");
            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("scope", scope + "");
            query.Add("state", state);

            // Construct the full URL
            return("https://api.vimeo.com/oauth/authorize?" + query);
        }
예제 #3
0
        /// <summary>
        /// Gets an app access token for for the application. The <see cref="ClientId"/> and <see cref="ClientSecret"/>
        /// properties must be specified for the OAuth client.
        /// </summary>
        /// <returns>An instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse GetAppAccessToken()
        {
            // Some validation
            if (string.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException(nameof(Version));
            }
            if (string.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (string.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }

            // Initialize the query string
            IHttpQueryString query = new HttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("client_secret", ClientSecret);
            query.Add("grant_type", "client_credentials");

            // Make the call to the API
            IHttpResponse response = HttpUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
예제 #4
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            IHttpQueryString query = new HttpQueryString();

            if (Desc)
            {
                query.Add("desc", "true");
            }
            if (Fields?.Count > 0)
            {
                query.Add("fields", Fields);
            }
            if (Page > 0)
            {
                query.Add("page", Page);
            }
            if (Offset > 0)
            {
                query.Add("offset", Offset);
            }
            // TODO: Add support for the "scroll" parameter

            if (Status != null && Status.Length > 0)
            {
                query.Add("status", String.Join(",", from status in Status select StringUtils.ToCamelCase(status)));
            }

            return(query);
        }
예제 #5
0
        public void GetProductsWithQueryStringRelative()
        {
            var serializer = new XmlSerializer(typeof(Crawler.Model.CJ.cjapi));

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("https://product-search.api.cj.com");

            HttpQueryString query = new HttpQueryString();

            query.Add("website-id", "3100204");
            query.Add("keywords", "DVD");
            query.Add("page-number", "1");
            query.Add("records-per-page", "1000");


            var uri = HttpQueryString.MakeQueryString(new Uri("/v2/product-search?", UriKind.Relative), query);
            var req = new HttpRequestMessage("GET", uri);

            req.Headers.Add("authorization", "00b171e48c4bc1e70836b252e1c4c40a893f19db0457be8447b1acdbdc0e7e769e1b804c1af54f883326d6147d1365f4b5f031a61740cf0c63a9f4b3d174cebbbf/420a385c3aa9bcd962b9f57ccf2583225758c11999aa6f42db8e90f9126fe0a7110790cd2ccd66a4f1861e89bd33fcfa6f528b494fa183f5d380ca289d18c309");

            using (var response = client.Send(req))
            {
                //string results = response.Content.ReadAsString();
                var extended = (object)serializer.Deserialize(response.Content.ReadAsStream());
            }
        }
예제 #6
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            // Either "GroupId" or "GroupPathAlias" should be specified
            if (string.IsNullOrWhiteSpace(GroupId + GroupPathAlias))
            {
                throw new PropertyNotSetException("GroupId");
            }

            // Append the options to the query string (if specified)
            HttpQueryString query = new HttpQueryString();

            query.Add("method", "flickr.groups.getInfo");
            if (!string.IsNullOrWhiteSpace(GroupId))
            {
                query.Add("group_id", GroupId);
            }
            if (!string.IsNullOrWhiteSpace(GroupPathAlias))
            {
                query.Add("group_path_alias", GroupPathAlias);
            }
            if (!string.IsNullOrWhiteSpace(Language))
            {
                query.Add("lang", Language);
            }

            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpQueryString"/>.</returns>
        public IHttpQueryString GetQueryString()
        {
            if (Id == 0)
            {
                throw new PropertyNotSetException(nameof(Id));
            }

            IHttpQueryString query = new HttpQueryString();

            query.Set("id", Id);
            if (TrimUser)
            {
                query.Add("trim_user", "true");
            }
            if (IncludeMyRetweet)
            {
                query.Add("include_my_retweet", "true");
            }
            if (IncludeEntities)
            {
                query.Add("include_entities", "true");
            }
            if (TweetMode != TwitterTweetMode.Compatibility)
            {
                query.Add("tweet_mode", StringUtils.ToCamelCase(TweetMode));
            }
            return(query);
        }
        /// <summary>
        /// Generates the authorization URL using the specified <paramref name="state"/> and <paramref name="scope"/>.
        /// </summary>
        /// <param name="state">The state to send to Meetups's OAuth login page.</param>
        /// <param name="scope">The scope of the application.</param>
        /// <returns>An authorization URL based on <paramref name="state"/> and <paramref name="scope"/>.</returns>
        public string GetAuthorizationUrl(string state, params string[] scope)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }

            // Do we have a valid "state" ?
            if (String.IsNullOrWhiteSpace(state))
            {
                throw new ArgumentNullException(nameof(state), "A valid state should be specified as it is part of the security of OAuth 2.0.");
            }

            IHttpQueryString query = new HttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("response_type", "code");
            query.Add("state", state);

            string s = String.Join("+", scope ?? new string[0]);

            if (!String.IsNullOrWhiteSpace(s))
            {
                query.Add("scope", s);
            }

            // Generate the authorization URL
            return("https://secure.meetup.com/oauth2/authorize?" + query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            // Either "GroupId" or "GroupPathAlias" should be specified
            if (string.IsNullOrWhiteSpace(GroupId))
            {
                throw new PropertyNotSetException(nameof(GroupId));
            }

            // Append the options to the query string (if specified)
            HttpQueryString query = new HttpQueryString {
                { "method", "flickr.groups.pools.getPhotos" },
                { "group_id", GroupId }
            };

            if (Extras != null && Extras.Count > 0)
            {
                query.Add("extras", string.Join(",", Extras));
            }

            if (PerPage > 0)
            {
                query.Add("per_page", PerPage);
            }
            if (Page > 0)
            {
                query.Add("page", Page);
            }

            return(query);
        }
        /// <inheritdoc />
        public IHttpRequest GetRequest()
        {
            // Make sure either Latitude or Longitude are specified ("0,0" is considered invalid)
            if (Math.Abs(Latitude) < double.Epsilon && Math.Abs(Longitude) < double.Epsilon)
            {
                throw new PropertyNotSetException(nameof(Latitude));
            }

            // Initialize the query string
            IHttpQueryString query = new HttpQueryString {
                { "location", string.Format(CultureInfo.InvariantCulture, "{0},{1}", Latitude, Longitude) }
            };

            // Append the language if specified
            if (Radius > 0)
            {
                query.Add("radius", Radius);
            }
            if (string.IsNullOrWhiteSpace(Keyword) == false)
            {
                query.Add("keyword", Keyword);
            }
            if (string.IsNullOrWhiteSpace(Language) == false)
            {
                query.Add("language", Language);
            }
            if (MinPrice != PlacesPriceLevel.Unspecified)
            {
                query.Add("minprice", (int)MinPrice - 1);
            }
            if (MaxPrice != PlacesPriceLevel.Unspecified)
            {
                query.Add("maxprice", (int)MaxPrice - 1);
            }
            if (string.IsNullOrWhiteSpace(Name) == false)
            {
                query.Add("name", Name);
            }
            query.Add("rankby", StringUtils.ToCamelCase(RankBy));
            if (string.IsNullOrWhiteSpace(Type) == false)
            {
                query.Add("type", Type);
            }
            if (string.IsNullOrWhiteSpace(PageToken) == false)
            {
                query.Add("pagetoken", PageToken);
            }
            if (Fields != null && Fields.Count > 0)
            {
                query.Add("fields", string.Join(",", Fields));
            }

            // Create the request
            return(HttpRequest.Get("https://maps.googleapis.com/maps/api/place/nearbysearch/json", query));
        }
        private void BuildRequest()
        {
            HttpQueryString query = new HttpQueryString();

            query.Add(Model.CJ.QueryConstants.WebsiteID, ConfigurationManager.AppSettings["cjSiteID"]);
            query.Add(Model.CJ.QueryConstants.PageNumber, "1");
            query.Add(Model.CJ.QueryConstants.RecordsPerPage, "1000");

            var uri = HttpQueryString.MakeQueryString(new Uri(METHOD, UriKind.Relative), query);

            request = new HttpRequestMessage("GET", uri);

            request.Headers.Add(Model.CJ.QueryConstants.Authorization, ConfigurationManager.AppSettings["cjDeveloperKey"]);
        }
예제 #12
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            // The place type must be specified
            if (PlaceType == FlickrPlaceType.Unknown)
            {
                throw new PropertyNotSetException("PlaceType");
            }

            // Either "WoeId" or "PlaceId" must be specified
            if (string.IsNullOrEmpty(WoeId + PlaceId))
            {
                throw new PropertyNotSetException("PlaceId");
            }

            HttpQueryString query = new HttpQueryString();

            query.Add("method", "flickr.places.placesForContacts");
            query.Add("place_type_id", (int)PlaceType);
            if (!string.IsNullOrEmpty(WoeId))
            {
                query.Add("woe_id", WoeId);
            }
            if (!string.IsNullOrEmpty(PlaceId))
            {
                query.Add("place_id", WoeId);
            }
            if (Threshold > 0)
            {
                query.Add("threshold", Threshold);
            }
            query.Add("contacts", Contacts == FlickrContactsMode.FriendsAndFamily ? "ff" : "all");
            if (MinUploadDate != null)
            {
                query.Add("min_upload_date", MinUploadDate.UnixTimestamp);
            }
            if (MaxUploadDate != null)
            {
                query.Add("max_upload_date", MaxUploadDate.UnixTimestamp);
            }
            if (MinTakenDate != null)
            {
                query.Add("min_taken_date", MinTakenDate.UnixTimestamp);
            }
            if (MaxTakenDate != null)
            {
                query.Add("max_taken_date", MaxTakenDate.UnixTimestamp);
            }

            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public virtual IHttpQueryString GetQueryString()
        {
            HttpQueryString query = new HttpQueryString();

            if (Page > 0)
            {
                query.Add("page", Page);
            }
            if (PerPage > 0)
            {
                query.Add("per_page", PerPage);
            }

            return(query);
        }
예제 #14
0
        public IHttpRequest GetRequest()
        {
            IHttpQueryString query = new HttpQueryString();

            if (StartIndex > 0)
            {
                query.Add("start-index", StartIndex);
            }
            if (MaxResults > 0)
            {
                query.Add("max-results", MaxResults);
            }

            return(HttpRequest.Get("/analytics/v3/management/accounts", query));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            // "GalleryId" must be specified
            if (string.IsNullOrWhiteSpace(GalleryId))
            {
                throw new PropertyNotSetException("GroupId");
            }

            // Append the options to the query string (if specified)
            HttpQueryString query = new HttpQueryString();

            query.Add("method", "flickr.galleries.getInfo");
            query.Add("gallery_id", GalleryId);

            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            HttpQueryString query = new HttpQueryString();

            query.Add("method", "flickr.galleries.create");
            return(query);
        }
예제 #17
0
        protected HttpQueryString GetDefaultQueryString()
        {
            HttpQueryString queryString = new HttpQueryString();

            queryString.Add("apiKey", ApiKey);
            return(queryString);
        }
        /// <summary>
        /// Following the 3-legged authorization, you can exchange a request token for an access token
        /// using this method. This is the third and final step of the authorization process.
        /// </summary>
        /// <param name="verifier">The verification key received after the user has accepted the app.</param>
        /// <returns>An instance of <see cref="OAuthAccessTokenResponse"/> representing the response.</returns>
        public override OAuthAccessTokenResponse GetAccessToken(string verifier)
        {
            // Flickr apparently deviates from the OAuth 1.0a specification, since they require the OAuth properties to
            // be specified in the query string.

            // Some error checking
            if (AccessTokenUrl == null)
            {
                throw new PropertyNotSetException("AccessTokenUrl");
            }
            if (ConsumerKey == null)
            {
                throw new PropertyNotSetException("ConsumerKey");
            }
            if (ConsumerSecret == null)
            {
                throw new PropertyNotSetException("ConsumerSecret");
            }
            if (Token == null)
            {
                throw new PropertyNotSetException("Token");
            }

            // Initialize the query string
            HttpQueryString queryString = new HttpQueryString {
                { "oauth_verifier", verifier }
            };

            // Generate the OAuth signature
            string signature = GenerateSignature(HttpMethod.Get, AccessTokenUrl, queryString, null);

            // Append the OAuth properties to the query string
            queryString.Add("oauth_nonce", Nonce);
            queryString.Add("oauth_timestamp", Timestamp);
            queryString.Add("oauth_consumer_key", ConsumerKey);
            queryString.Add("oauth_signature_method", "HMAC-SHA1");
            queryString.Add("oauth_version", "1.0");
            queryString.Add("oauth_token", Token);
            if (!string.IsNullOrWhiteSpace(Callback))
            {
                queryString.Add("oauth_callback", Callback);
            }
            queryString.Add("oauth_signature", signature);

            // Make the call to the API
            IHttpResponse response = HttpUtils.Requests.Get(AccessTokenUrl, queryString);

            // Validate the response
            FlickrResponse.ValidateResponse(response);

            // Parse the response body
            OAuthAccessToken body = OAuthAccessToken.Parse(this, response.Body);

            // Parse the response
            return(OAuthAccessTokenResponse.ParseResponse(response, body));
        }
예제 #19
0
        internal IHttpQueryString GetQueryString(GoogleOAuthClient client)
        {
            // Validate the required parameters and properties
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (string.IsNullOrWhiteSpace(State))
            {
                throw new PropertyNotSetException(nameof(State));
            }
            if (string.IsNullOrWhiteSpace(client.ClientId))
            {
                throw new PropertyNotSetException(nameof(client.ClientId));
            }
            if (string.IsNullOrWhiteSpace(client.RedirectUri))
            {
                throw new PropertyNotSetException(nameof(client.RedirectUri));
            }

            // Generate the query string
            IHttpQueryString query = new HttpQueryString();

            query.Add("response_type", "code");
            query.Add("client_id", client.ClientId);
            query.Add("access_type", StringUtils.ToUnderscore(AccessType));
            query.Add("prompt", ToString(Prompt));
            query.Add("scope", Scope + string.Empty);
            query.Add("redirect_uri", client.RedirectUri);
            query.Add("state", State);

            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpQueryString"/>.</returns>
        public IHttpQueryString GetQueryString()
        {
            IHttpQueryString query = new HttpQueryString();

            if (!IncludeEntities)
            {
                query.Add("include_entities", "false");
            }
            if (SkipStatus)
            {
                query.Add("skip_status", "true");
            }
            if (IncludeEmail)
            {
                query.Add("include_email", "true");
            }
            return(query);
        }
        /// <summary>
        /// Gets debug information about the specified access token.
        /// </summary>
        /// <param name="accessToken">The access token to debug.</param>
        /// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
        public IHttpResponse DebugToken(string accessToken)
        {
            // Declare the query string
            IHttpQueryString query = new HttpQueryString();

            query.Add("input_token", accessToken);

            // Make the call to the API
            return(Client.DoHttpGetRequest("/debug_token", query));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            HttpQueryString query = new HttpQueryString();

            query.Add("method", "flickr.galleries.getList");
            if (!string.IsNullOrWhiteSpace(UserId))
            {
                query.Add("user_id ", UserId);
            }
            if (PerPage > 0)
            {
                query.Add("per_page ", PerPage);
            }
            if (Page > 0)
            {
                query.Add("page ", Page);
            }
            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            if (string.IsNullOrWhiteSpace(UserId))
            {
                throw new PropertyNotSetException("UserId");
            }
            HttpQueryString query = new HttpQueryString();

            query.Add("method", "flickr.photosets.getList");
            query.Add("user_id", UserId);
            if (Page > 0)
            {
                query.Add("page", Page);
            }
            if (PerPage > 0)
            {
                query.Add("per_page", PerPage);
            }
            return(query);
        }
예제 #24
0
        /// <inheritdoc />
        public IHttpRequest GetRequest()
        {
            IHttpQueryString query = new HttpQueryString();

            if (Fields != null && Fields.Count > 0)
            {
                query.Add("fields", Fields);
            }

            return(HttpRequest.Get($"/{(UserId == 0 ? "me" : UserId.ToString())}", query));
        }
        public IHttpRequest GetRequest()
        {
            if (string.IsNullOrWhiteSpace(AccountId))
            {
                throw new PropertyNotSetException(nameof(AccountId));
            }

            IHttpQueryString query = new HttpQueryString();

            if (StartIndex > 0)
            {
                query.Add("start-index", StartIndex);
            }
            if (MaxResults > 0)
            {
                query.Add("max-results", MaxResults);
            }

            return(HttpRequest.Get($"/analytics/v3/management/accounts/{AccountId}/webproperties", query));
        }
예제 #26
0
        /// <inheritdoc />
        public IHttpRequest GetRequest()
        {
            HttpQueryString query = new HttpQueryString();

            if (Part != null)
            {
                query.Add("part", Part.ToString());
            }
            if (!string.IsNullOrWhiteSpace(ChannelId))
            {
                query.Add("channelId", ChannelId);
            }
            if (Ids != null && Ids.Length > 0)
            {
                query.Add("id", string.Join(",", Ids));
            }
            if (MaxResults > 0)
            {
                query.Add("maxResults", MaxResults);
            }
            if (Mine)
            {
                query.Add("mine", "true");
            }
            if (!string.IsNullOrWhiteSpace(PageToken))
            {
                query.Add("pageToken", PageToken);
            }

            return(HttpRequest.Get("https://www.googleapis.com/youtube/v3/playlists", query));
        }
예제 #27
0
        public void GetProductsWithQueryStringRelative()
        {
            var serializer = new XmlSerializer(typeof(Crawler.Model.LinkShare.result));

            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://feed.linksynergy.com");

            HttpQueryString query = new HttpQueryString();
            query.Add("token", "5bfb339580a02308573204c2ac1bb921ecba09ba542a19d271c2d7e9c27a509f");
            query.Add("keyword", "DVD Player");
            query.Add("Page", "1");
            query.Add("MaxResults", "100");

            var uri = HttpQueryString.MakeQueryString(new Uri("/productsearch?", UriKind.Relative), query);
            var req = new HttpRequestMessage("GET", uri);

            using (var response = client.Send(req))
            {
                //string results = response.Content.ReadAsString();
                var extended = (object)serializer.Deserialize(response.Content.ReadAsStream());
            }
        }
        /// <inheritdoc />
        public IHttpRequest GetRequest()
        {
            if (Location == null)
            {
                throw new PropertyNotSetException(nameof(Location));
            }

            // Make sure either Latitude or Longitude are specified ("0,0" is considered invalid)
            if (Math.Abs(Location.Latitude) < double.Epsilon && Math.Abs(Location.Longitude) < double.Epsilon)
            {
                throw new PropertyNotSetException(nameof(Location.Latitude));
            }

            // Initialize the query string
            IHttpQueryString query = new HttpQueryString();

            if (string.IsNullOrWhiteSpace(Query) == false)
            {
                query.Add("query", Query);
            }
            query.Add("location", string.Format(CultureInfo.InvariantCulture, "{0},{1}", Location.Latitude, Location.Longitude));
            if (Radius > 0)
            {
                query.Add("radius", Radius);
            }
            if (string.IsNullOrWhiteSpace(Language) == false)
            {
                query.Add("language", Language);
            }
            if (MinPrice != PlacesPriceLevel.Unspecified)
            {
                query.Add("minprice", (int)MinPrice - 1);
            }
            if (MaxPrice != PlacesPriceLevel.Unspecified)
            {
                query.Add("maxprice", (int)MaxPrice - 1);
            }
            if (string.IsNullOrWhiteSpace(Type) == false)
            {
                query.Add("type", Type);
            }
            if (string.IsNullOrWhiteSpace(PageToken) == false)
            {
                query.Add("pagetoken", PageToken);
            }

            // Create the request
            return(HttpRequest.Get("https://maps.googleapis.com/maps/api/place/textsearch/json", query));
        }
예제 #29
0
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Facebook OAuth dialog.</param>
        /// <returns>An instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (string.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException(nameof(Version));
            }
            if (string.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (string.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }
            if (string.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }
            if (string.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException(nameof(authCode));
            }

            // Initialize the query string
            IHttpQueryString query = new HttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("client_secret", ClientSecret);
            query.Add("code", authCode);

            // Make the call to the API
            IHttpResponse response = HttpUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
        /// <inheritdoc />
        public IHttpRequest GetRequest()
        {
            IHttpQueryString query = new HttpQueryString();

            if (Fields != null && Fields.Count > 0)
            {
                query.Add("fields", Fields);
            }
            if (Limit > 0)
            {
                query.Add("limit", Limit);
            }
            if (string.IsNullOrWhiteSpace(After) == false)
            {
                query.Add("after", After);
            }
            if (string.IsNullOrWhiteSpace(Before) == false)
            {
                query.Add("before", Before);
            }

            return(HttpRequest.Get($"/{(UserId == 0 ? "me" : UserId.ToString())}/media", query));
        }
        public void GetProductsWithQueryStringRelative()
        {
            var serializer = new XmlSerializer(typeof(Crawler.Model.CJ.cjapi));

            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://product-search.api.cj.com");

            HttpQueryString query = new HttpQueryString();
            query.Add("website-id", "3100204");
            query.Add("keywords", "DVD");
            query.Add("page-number", "1");
            query.Add("records-per-page", "1000");

            var uri = HttpQueryString.MakeQueryString(new Uri("/v2/product-search?", UriKind.Relative), query);
            var req = new HttpRequestMessage("GET", uri);
            req.Headers.Add("authorization", "00b171e48c4bc1e70836b252e1c4c40a893f19db0457be8447b1acdbdc0e7e769e1b804c1af54f883326d6147d1365f4b5f031a61740cf0c63a9f4b3d174cebbbf/420a385c3aa9bcd962b9f57ccf2583225758c11999aa6f42db8e90f9126fe0a7110790cd2ccd66a4f1861e89bd33fcfa6f528b494fa183f5d380ca289d18c309");

            using (var response = client.Send(req))
            {
                //string results = response.Content.ReadAsString();
                var extended = (object)serializer.Deserialize(response.Content.ReadAsStream());
            }
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpQueryString"/>.</returns>
        public IHttpQueryString GetQueryString()
        {
            // Define the query string
            IHttpQueryString qs = new HttpQueryString();

            // Add optional parameters
            if (UserId > 0)
            {
                qs.Set("user_id", UserId);
            }
            if (!String.IsNullOrWhiteSpace(ScreenName))
            {
                qs.Set("screen_name", ScreenName);
            }
            if (SinceId > 0)
            {
                qs.Set("since_id", SinceId);
            }
            if (Count > 0)
            {
                qs.Set("count", Count);
            }
            if (MaxId > 0)
            {
                qs.Set("max_id", MaxId);
            }
            if (TrimUser)
            {
                qs.Set("trim_user", "true");
            }
            if (ExcludeReplies)
            {
                qs.Set("exclude_replies", "true");
            }
            if (ContributorDetails)
            {
                qs.Set("contributor_details", "true");
            }
            if (!IncludeRetweets)
            {
                qs.Set("include_rts", "false");
            }
            if (TweetMode != TwitterTweetMode.Compatibility)
            {
                qs.Add("tweet_mode", StringUtils.ToCamelCase(TweetMode));
            }

            return(qs);
        }
예제 #33
0
파일: FacebookClient.cs 프로젝트: tvene/HPB
        public AccessToken GetAccessToken(string verificationCode, string redirectUri)
        {
            var getAccessTokenUrl = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/oauth/access_token", UrlResources.GraphApiUrl));
            var queryString = new HttpQueryString();
            queryString.Add("client_id", this.AppId);
            queryString.Add("redirect_uri", redirectUri);
            queryString.Add("client_secret", this.AppSecret);
            queryString.Add("code", verificationCode);

            using (HttpClient client = new HttpClient())
            {
                using (var response = client.Get(getAccessTokenUrl, queryString).EnsureStatusIsSuccessful())
                {
                    var content = response.Content.ReadAsString();
                    var qs = HttpUtility.ParseQueryString(content);

                    return new AccessToken
                                {
                                    Token = qs["access_token"],
                                    Expires = qs["expires"] != null ? long.Parse(qs["expires"]) : new Nullable<long>()
                                };
                }
            }
        }
예제 #34
0
파일: FacebookClient.cs 프로젝트: tvene/HPB
        public IEnumerable<Status> GetUserStatus(string token, int count)
        {
            var userStatusGetUrl = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/me/statuses", UrlResources.GraphApiUrl));

            var queryString = new HttpQueryString();
            queryString.Add("access_token", token);
            queryString.Add("limit", count.ToString());

            using (HttpClient client = new HttpClient())
            {
                using (var response = client.Get(userStatusGetUrl, queryString).EnsureStatusIsSuccessful())
                {
                    var status = response.Content.ReadAsJsonDataContract<ArrayOfStatus>();
                    return status.UserStatuses.ToList();
                }
            }
        }
예제 #35
0
파일: FacebookClient.cs 프로젝트: tvene/HPB
        public User GetUser(string accessToken)
        {
            var userProfileUrl = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/me", UrlResources.GraphApiUrl));

            var queryString = new HttpQueryString();
            queryString.Add("access_token", accessToken);

            using (HttpClient client = new HttpClient())
            {
                using (var response = client.Get(userProfileUrl, queryString).EnsureStatusIsSuccessful())
                {
                    var userProfile = response.Content.ReadAsJsonDataContract<User>();
                    return userProfile;
                }
            }
        }
예제 #36
0
        /**
         *  Get file content
         *  TODO: range query?
         */
        public Stream getFile(string path)
        {
            // remove leading slash
            path = stripLeadingSlash(path);

            if (gdocsLinkExtension && path.EndsWith(".url"))
            {
                path = path.Substring(0, path.Length - 4);
                Metadata metadata = metadataCache[path];
                if (metadata != null && metadata.gdocs_link!=null)
                {
                    return createUrlFileContent(metadata.gdocs_link);
                }
            }
            HttpClient http = new HttpClient(baseUri);
            HttpQueryString query = new HttpQueryString();
            query.Add("oauth_token", token.access_token);
            Uri contentUri = new Uri(string.Format("files/{0}", Uri.EscapeUriString(path)), UriKind.Relative);
            HttpResponseMessage resp = http.Get(contentUri, query);
            if (resp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return new MemoryStream(resp.Content.ReadAsByteArray(), false);
            }
            else if (resp.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                throw new NotFoundException();
            }
            else
            {
                throw new BadRequestException();
            }
        }
예제 #37
0
        /**
         * Retrieve metadata from CSP
         * includes simple caching
         */
        public Metadata getMetadata(string path, bool list=true)
        {
            path = stripLeadingSlash(path);
            if (gdocsLinkExtension && path.EndsWith(".url"))
            {
                path = path.Substring(0, path.Length-4);
            }
            // check metadata cache
            Metadata metadata = metadataCache[path];
            if (metadata != null)
            {
                System.Diagnostics.Debug.Print("MetadataCache hit! {0}", path);
                return metadata;
            }

            HttpClient http = new HttpClient(baseUri);
            HttpQueryString query = new HttpQueryString();
            if (list)
            {
                query.Add("list", list.ToString());
            }
            query.Add("oauth_token", token.access_token);
            Uri metadataUri = new Uri(string.Format("metadata/{0}", Uri.EscapeUriString(path)),UriKind.Relative);
            HttpResponseMessage resp = http.Get(metadataUri, query);
            if (resp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                if (gdocsLinkExtension)
                {
                    metadata = resp.Content.ReadAsJsonDataContract<Metadata>();
                    PlaceUrlFiles(metadata);
                }
                else
                {
                    metadata = resp.Content.ReadAsJsonDataContract<Metadata>();
                }
                metadataCache[path] = metadata;
                return metadata;
            }
            else if (resp.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                throw new NotFoundException();
            }
            else
            {
                throw new BadRequestException();
            }
        }
        private void BuildRequest()
        {
            HttpQueryString query = new HttpQueryString();
            query.Add(Model.CJ.QueryConstants.WebsiteID, ConfigurationManager.AppSettings["cjSiteID"]);
            query.Add(Model.CJ.QueryConstants.PageNumber, "1");
            query.Add(Model.CJ.QueryConstants.RecordsPerPage, "1000");

            var uri = HttpQueryString.MakeQueryString(new Uri(METHOD, UriKind.Relative), query);
            request = new HttpRequestMessage("GET", uri);

            request.Headers.Add(Model.CJ.QueryConstants.Authorization, ConfigurationManager.AppSettings["cjDeveloperKey"]);
        }