<commit_before>package org.springframework.social.facebook;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

/**
 * This is the central class for interacting with Facebook.
 * 
 * @author <NAME>
 */
public class FacebookTemplate implements FacebookOperations {
	private RestOperations restOperations;
	private final String accessToken;

	/**
	 * Create a new instance of FacebookTemplate.
	 * 
	 * This constructor creates the FacebookTemplate using a given access token.
	 * 
	 * @param accessToken
	 *            An access token given by Facebook after a successful OAuth 2
	 *            authentication (or through Facebook's JS library).
	 */
	public FacebookTemplate(String accessToken) {
		this.accessToken = accessToken;
		RestTemplate restTemplate = new RestTemplate();
		MappingJacksonHttpMessageConverter json = new MappingJacksonHttpMessageConverter();
		json.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "javascript")));
		restTemplate.getMessageConverters().add(json);
		this.restOperations = restTemplate;
	}

	public String getProfileId() {
		return Long.toString(getUserInfo().getId());
	}

	public FacebookUserInfo getUserInfo() {
		return restOperations.getForObject(OBJECT_URL + "?access_token={accessToken}", FacebookUserInfo.class, "me",
				accessToken);
    }

	public List<String> getFriendIds() {
		@SuppressWarnings("rawtypes")
		ResponseEntity<Map> response = restOperations.getForEntity(CONNECTION_URL, Map.class, CURRENT_USER, FRIENDS,
				accessToken);
<commit_msg>Use Commons request factory in FacebookTemplate or else 302 responses won't be followed for profile images.<commit_after>package org.springframework.social.facebook;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.CommonsClientHttpRequestFactory;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

/**
 * This is the central class for interacting with Facebook.
 * 
 * @author <NAME>
 */
public class FacebookTemplate implements FacebookOperations {
	private RestOperations restOperations;
	private final String accessToken;

	/**
	 * Create a new instance of FacebookTemplate.
	 * 
	 * This constructor creates the FacebookTemplate using a given access token.
	 * 
	 * @param accessToken
	 *            An access token given by Facebook after a successful OAuth 2
	 *            authentication (or through Facebook's JS library).
	 */
	public FacebookTemplate(String accessToken) {
		this.accessToken = accessToken;
		RestTemplate restTemplate = new RestTemplate();
		// must be CommonsClientHttpRequestFactory or else the location header
		// in an HTTP 302 won't be followed
		restTemplate.setRequestFactory(new CommonsClientHttpRequestFactory());
		MappingJacksonHttpMessageConverter json = new MappingJacksonHttpMessageConverter();
		json.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "javascript")));
		restTemplate.getMessageConverters().add(json);
		this.restOperations = restTemplate;
	}

	public String getProfileId() {
		return Long.toString(getUserInfo().getId());
	}

	public FacebookUserInfo getUserInfo() {
		return restOperations.getForObject(OBJECT_URL + "?access_token={accessToken}", FacebookUserInfo.class, "me",
				accessToken);
    }

	public List<String> getFriendIds() {
		@SuppressWarnings("rawtypes")
		ResponseEntity<Map> response = restOperations.getForEntity(CONNECTION_URL, Map.class, CURRENT_USER, FRIENDS,
				accessToken);

{'fraction_non_alphanumeric': 0.0893194706994329, 'fraction_numerical': 0.001890359168241966, 'mean_word_length': 5.423368740515933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5453209', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1100, 'n_words': 286}