public static string GetAccessToken(SDK sdk) { if (string.IsNullOrEmpty(sdk.ClientId) || string.IsNullOrEmpty(sdk.ClientSecret)) { throw new MPException("\"client_id\" and \"client_secret\" can not be \"null\" when getting the \"access_token\""); } MPAPIResponse mpapiResponse = new MPRESTClient().ExecuteRequest(HttpMethod.POST, sdk.BaseUrl + "/oauth/token", PayloadType.X_WWW_FORM_URLENCODED, new JObject() { { "grant_type", (JToken)"client_credentials" }, { "client_id", (JToken)sdk.ClientId }, { "client_secret", (JToken)sdk.ClientSecret } }, (WebHeaderCollection)null, 0, 0); JObject containerToken = JObject.Parse(mpapiResponse.StringResponse.ToString()); if (mpapiResponse.StatusCode != 200) { throw new MPException("Can not retrieve the \"access_token\""); } List <JToken> tokens1 = containerToken.FindTokens("access_token"); List <JToken> tokens2 = containerToken.FindTokens("refresh_token"); if (tokens1 == null || tokens1.Count != 1) { throw new MPException("Can not retrieve the \"access_token\""); } string str = tokens1.First <JToken>().ToString(); if (tokens2 != null && tokens2.Count == 1) { sdk.RefreshToken = tokens2.First <JToken>().ToString(); } return(str); }
internal static MPAPIResponse Invoke(HttpMethod httpMethod, string path, PayloadType payloadType, JObject payload, string accessToken, Dictionary <string, string> queryParameters, bool useCache, int requestTimeout, int retries) { path = CreatePath(path, accessToken, queryParameters); var cacheKey = GetCacheKey(httpMethod, path); var response = TryGetFromCache(useCache, cacheKey); if (response == null) { response = new MPRESTClient().ExecuteRequest( httpMethod, path, payloadType, payload, true, requestTimeout, retries); TryAddToCache(useCache, cacheKey, response); } return(response); }
public static JToken Put(string uri, JObject payload) { MPRESTClient client = new MPRESTClient(); return(client.ExecuteGenericRequest(HttpMethod.PUT, uri, PayloadType.JSON, payload)); }
public static JToken Get(String uri) { MPRESTClient client = new MPRESTClient(); return(client.ExecuteGenericRequest(HttpMethod.GET, uri, PayloadType.JSON, null)); }
public MPRESTClient() { MPRESTClient mprestClient = new MPRESTClient((string)null, -1); }