示例#1
0
  /**
   * Get response from Instagram.
   *
   * @param verb HTTP Verb
   * @param methodName Instagram API Method
   * @param params parameters which would be sent with the request.
   * @return Response object.
   */
  protected Response getApiResponse(Verbs verb, String methodName, Map<String, String> params)
      throws IOException {
    Response response;
    String apiResourceUrl = config.getApiURL() + methodName;
    OAuthRequest request = new OAuthRequest(verb, apiResourceUrl);

    request.setConnectTimeout(config.getConnectionTimeoutMills(), TimeUnit.MILLISECONDS);
    request.setReadTimeout(config.getReadTimeoutMills(), TimeUnit.MILLISECONDS);

    if (enforceSignatrue != null) {
      request.addHeader(EnforceSignedHeaderUtils.ENFORCE_SIGNED_HEADER, enforceSignatrue);
    }

    if (requestProxy != null) {
      request.setProxy(requestProxy);
    }

    // Additional parameters in url
    if (params != null) {
      for (Map.Entry<String, String> entry : params.entrySet()) {
        if (verb == Verbs.GET) {
          request.addQuerystringParameter(entry.getKey(), entry.getValue());
        } else {
          request.addBodyParameter(entry.getKey(), entry.getValue());
        }
      }
    }

    // Add the AccessToken to the Request Url
    if ((verb == Verbs.GET) || (verb == Verbs.DELETE)) {
      if (accessToken == null) {
        request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientId);
      } else {
        request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
      }
    } else {
      if (accessToken == null) {
        request.addBodyParameter(OAuthConstants.CLIENT_ID, clientId);
      } else {
        request.addBodyParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
      }
    }

    response = request.send();

    return response;
  }
示例#2
0
  /**
   * Get response from Instagram.
   *
   * @param verb HTTP Verb
   * @param methodName Instagram API Method
   * @param params parameters which would be sent with the request.
   * @return Response object.
   */
  private Response getApiResponse(Verbs verb, String methodName, Map<String, String> params)
      throws IOException {
    Response response = null;
    String apiResourceUrl = Constants.API_URL + methodName;
    OAuthRequest request = new OAuthRequest(verb, apiResourceUrl);

    // Additional parameters in url
    if (params != null) {
      for (Map.Entry<String, String> entry : params.entrySet()) {
        if (verb == Verbs.GET) {
          request.addQuerystringParameter(entry.getKey(), entry.getValue());
        } else {
          request.addBodyParameter(entry.getKey(), entry.getValue());
        }
      }
    }

    // Add the AccessToken to the Request Url
    if ((verb == Verbs.GET) || (verb == Verbs.DELETE)) {
      if (accessToken == null) {
        request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientId);
      } else {
        request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
      }
    } else {
      if (accessToken == null) {
        request.addBodyParameter(OAuthConstants.CLIENT_ID, clientId);
      } else {
        request.addBodyParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
      }
    }

    response = request.send();

    return response;
  }