HttpResponse httpResponse = null; String responseContent = null; BotMillNetworkResponse response = new BotMillNetworkResponse(); logger.error("HTTP connection failed with error code {}.", statusCode); response.setError(true); response.setResponse(responseContent); return response;
/** * GETs the daily unique conversation counts. * * @return the daily unique conversation counts. */ public static DailyUniqueConversationCounts getDailyUniqueConversationCounts() { String pageToken = FbBotMillContext.getInstance().getPageToken(); BotMillNetworkResponse response = NetworkUtils .get(FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSAGING_INSIGHT_CONVERSATION_URL + pageToken); return FbBotMillJsonUtils.fromJson(response.getResponse(), DailyUniqueConversationCounts.class); }
String output = response.getResponse(); if (response.isError()) {
/** * GETs the daily unique active thread counts. * * @return the daily unique active thread counts. */ public static DailyUniqueActiveThreadCounts getDailyUniqueActiveThreadCounts() { String pageToken = FbBotMillContext.getInstance().getPageToken(); BotMillNetworkResponse response = NetworkUtils .get(FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSAGING_INSIGHT_ACTIVE_THREADS_URL + pageToken); return FbBotMillJsonUtils.fromJson(response.getResponse(), DailyUniqueActiveThreadCounts.class); }
/** * Method used to retrieve a {@link FacebookUserProfile} from an ID using * the GET method. * * @param userId * the ID of the user to retrieve. * @return the user profile info. */ public static FacebookUserProfile getUserProfile(String userId) { String pageToken = FbBotMillContext.getInstance().getPageToken(); BotMillNetworkResponse response = NetworkUtils .get(FbBotMillNetworkConstants.FACEBOOK_BASE_URL + userId + FbBotMillNetworkConstants.USER_PROFILE_FIELDS + pageToken); FacebookUserProfile user = FbBotMillJsonUtils.fromJson( response.getResponse(), FacebookUserProfile.class); return user; }
/** * POSTs a messenger code as a JSON string to Facebook. * * @param input * the JSON data to send. * @return the requested messenger code. */ public static MessengerCode postMessengerCode(StringEntity input) { String pageToken = FbBotMillContext.getInstance().getPageToken(); // If the page token is invalid, returns. if (!validatePageToken(pageToken)) { return null; } String url = FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSENGER_CODE_API_URL + pageToken; BotMillNetworkResponse response = postInternal(url, input); // Parses the response as a MessengerCode and returns it. return FbBotMillJsonUtils.fromJson(response.getResponse(), MessengerCode.class); }
/** * POSTs an attachment as a JSON string to Facebook. * * @param input * the JSON data to send. * @return the uploaded attachment ID. */ public static UploadAttachmentResponse postUploadAttachment( StringEntity input) { String pageToken = FbBotMillContext.getInstance().getPageToken(); // If the page token is invalid, returns. if (!validatePageToken(pageToken)) { return null; } String url = FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_UPLOAD_API_URL + pageToken; BotMillNetworkResponse response = postInternal(url, input); // Parses the response as a UploadAttachmentResponse and returns it. return FbBotMillJsonUtils.fromJson(response.getResponse(), UploadAttachmentResponse.class); }