function tdr_promotions_social_media_scraper($social_network)
{
    // Get list of campaigns
    $promotion = new tdr_promotions();
    $campaign_list = $promotion->get_the_decoded_promotions();
    // Run Scrape for $campaign_slug with contest page url $contest_permalink
    foreach ($campaign_list as $campaign_slug => $campaign_data) {
        if ($campaign_data['campaign_ready'] === true) {
            // Only scrape campaigns in production status
            // Find contest page permalink based on campaign slug
            // Get list of pages with the contest template
            $contest_page_list = get_pages(array('meta_key' => '_wp_page_template', 'meta_value' => 'template-contest-' . $campaign_slug . '.php', 'hierarchical' => false));
            $contest_page_found = false;
            foreach ($contest_page_list as $contest_page) {
                if ($campaign_data['url_slug'] === $contest_page->post_name) {
                    $contest_page_id = $contest_page->ID;
                    $contest_page_found = true;
                    break;
                }
            }
            if ($contest_page_found) {
                $contest_permalink = get_permalink($contest_page_id);
                // Contest permalink for scraping
            }
            $db_slug = str_replace('-', '_', $campaign_slug);
            switch ($social_network) {
                case 'facebook':
                    $api_base_url = 'https://graph.facebook.com/search';
                    $transient_name = 'tdr_promo_fb_scr_' . $db_slug;
                    /*
                    $site_title_format = get_option( 'tdr_promotions_site_title_function' ); // Get title function for site -- extract from within
                    // Site title function is defined and is callable
                    if ( ( false !== $site_title_format ) && ( function_exists( $site_title_format ) ) ) {
                    	$contest_page_title = $site_title_format( $contest_page->ID );
                    	$contest_page_title = str_replace('|', '\\|', $contest_page_title );
                    }
                    // Fallback to page title
                    else {
                    	$contest_page_title = get_the_title( $contest_page->ID );
                    }
                    */
                    // DEBUG echo( 'using ' . $contest_page_title . ' for facebook scrapes' );
                    $request_array = array('q' => $campaign_data['facebook_share_title'], 'type' => 'post', 'access_token' => '', 'limit' => '100', 'date_format' => 'U');
                    break;
                default:
                    return;
            }
            // If transient not set, do new query
            $refresh_api_query = get_transient($transient_name);
            if (true) {
                // DEBUG echo('no transient found');
                switch ($social_network) {
                    case 'facebook':
                        $api_request = $api_base_url . '?' . http_build_query($request_array);
                        break;
                }
                // END STANDARD QUERY
            } else {
                // DEBUG echo('transient was found');
                switch ($social_network) {
                    case 'facebook':
                        $api_request = $refresh_api_query;
                        // Transient holds full request url
                        break;
                }
            }
            // Perform API GET request
            // DEBUG echo('making request to '. $api_request );
            $wp_remote_get_args = array('method' => 'GET', 'timeout' => 25, 'redirection' => 5, 'user-agent' => 'tdr-promos/1.0', 'blocking' => true, 'compress' => true, 'decompress' => true, 'sslverify' => true, 'httpversion' => '1.1', 'headers' => array(), 'body' => null, 'cookies' => array());
            $request_results = wp_remote_get($api_request, $wp_remote_get_args);
            // On errors, retry with exponential backing off
            $wait_time = 1;
            while (is_wp_error($request_results)) {
                // Api request failure -- retry with exponential backing off
                sleep($wait_time);
                $request_results = wp_remote_get($api_request, $wp_remote_get_args);
                if ($wait_time > 600) {
                    return;
                    // End function on repeated errors beyond 10 minutes retry wait ( aggregate of 21 minutes after timeouts )
                }
                $wait_time = $wait_time * 2;
                /*DEBUG var_dump( $request_results );
                		echo( 'first request died' );
                		echo( '<br>' . $api_request ); */
            }
            $parsed_results = json_decode($request_results['body'], true);
            // Parse response JSON
            // Update transient with refresh URL
            switch ($social_network) {
                case 'facebook':
                    if (!empty($parsed_results['data'])) {
                        // Get unix timestamp of most recent result
                        $most_recent_result = $parsed_results['data'][0]['created_time'];
                        // Most recent result is returned first by fb graph api
                        $request_array['since'] = $most_recent_result;
                        // Add since parameter to request array
                        $refresh_query = $api_base_url . '?' . http_build_query($request_array);
                        // Build url for api refresh request
                    } else {
                        $refresh_query = $api_request;
                        // Next time repeat a normal query if there were no results this time
                    }
                    break;
            }
            set_transient($transient_name, $refresh_query, 60 * 60 * 24 * 7);
            // Give transient an expiration of a week
            $referral_id_list = array();
            // Create empty array to hold referall ids from search results
            // Look through the search results
            switch ($social_network) {
                case 'facebook':
                    $i = 0;
                    // Set a loop counter so pagination links can be followed after the first iteration
                    $pagination_api_request = '';
                    // Set a variable for holding pagination urls in scope for all iterations of the loop
                    $time_array = array();
                    while (true) {
                        // Loop until the results are empty
                        if ($i > 4) {
                            break;
                        }
                        // Follow pagination links for new iterations of the loop
                        if ($i > 0) {
                            /* PROFILING CODE
                            			// Start time logging*/
                            //$start_time = microtime( true );
                            $request_results = wp_remote_get($pagination_api_request, $wp_remote_get_args);
                            //$end_time = microtime( true );
                            //$execution_time = round( $end_time - $start_time, 4 );
                            //$time_array [] = $execution_time;
                            // END PROFILING CODE
                            $timeout = false;
                            $wait_time = 1;
                            while (is_wp_error($request_results)) {
                                // Api request failure -- retry with exponential backing off
                                sleep($wait_time);
                                $request_results = wp_remote_get($pagination_api_request, $wp_remote_get_args);
                                if ($wait_time > 150) {
                                    $timeout = true;
                                    break;
                                    // End function on repeated errors beyond 2.5 minutes retry wait ( aggregate of ~7.5 minutes after timeouts )
                                }
                                $wait_time = $wait_time * 2;
                                /* DEBUG echo( 'died at iteration ' . $i );
                                			var_dump( $pagination_api_request );
                                			var_dump( $request_results ); */
                            }
                            if ($timeout) {
                                break;
                                // Stop scraping and process any collected entries
                            }
                            $parsed_results = json_decode($request_results['body'], true);
                            // Parse response JSON
                        }
                        // Get pagination link, if any
                        if (array_key_exists('paging', $parsed_results)) {
                            $pagination_link = $parsed_results['paging']['next'];
                            $pagination_api_request = $pagination_link;
                        } else {
                            break;
                            // End of results-- end loop
                        }
                        // Filter the pagination so only non-scraped results are shown
                        $url_params = parse_url($api_request, PHP_URL_QUERY);
                        // Get query string from link
                        parse_str($url_params, $url_param_array);
                        // Parse query string into array
                        if (array_key_exists('since', $url_param_array)) {
                            // Check if there was a since parameter in the original request
                            $pagination_api_request .= '&since=' . $url_param_array['since'];
                            // Append it to facebook's suggested pagination links
                        }
                        // Loop through the results for the current page
                        foreach ($parsed_results['data'] as $result) {
                            // Look for relevant entity
                            $url_params = parse_url($result['link'], PHP_URL_QUERY);
                            // Get query string from link
                            parse_str($url_params, $url_param_array);
                            // Parse query string into array
                            if (array_key_exists('ref', $url_param_array)) {
                                // 'ref' param was found
                                $located_referral_id = $url_param_array['ref'];
                                // Add to list
                                $located_referral_id = strtoupper($located_referral_id);
                                // Capitalize referral ids just in case
                                // User previously found in results
                                if (array_key_exists($located_referral_id, $referral_id_list)) {
                                    $referral_id_list[$located_referral_id]++;
                                    // Increment user's count
                                } else {
                                    $referral_id_list[$located_referral_id] = 1;
                                    // Add referral id to list
                                }
                            } else {
                                // Not found
                                // DEBUG echo('no match');
                            }
                        }
                        $i++;
                        // Increment loop counter
                        sleep(1);
                        // Be nice to facebook and impose a rate limit of 1 second between loops
                    }
                    // Write to /tmp
                    break;
            }
            /*
             * PROFILING CODE
            $fp = fopen('/tmp/twitterscrape.txt', 'w');
            fwrite($fp, $i);
            fwrite($fp, "\n min " . min( $time_array ) . " / max " . max( $time_array ) . " / average " . array_sum($time_array) / count(array_filter($time_array)) . " /  total " . array_sum( $time_array ) );
            fclose($fp);
            */
            // DEBUG var_dump( $referral_id_list );
            // User query for referral ID IN list
            // Credit with tweet/facebook post
            $query_referral_id_list = array_keys($referral_id_list);
            // Define the wordpress user query parameters
            $contest_user_query_args = array('role' => 'promo-' . $campaign_slug, 'meta_key' => 'referral_id', 'meta_value' => $query_referral_id_list, 'meta_compare' => 'IN');
            // Perform the user query
            $contest_user_query = new WP_User_Query($contest_user_query_args);
            // If results found, fetch them
            if ($contest_user_query->total_users != "0") {
                $contest_users_from_scrape = $contest_user_query->get_results();
                foreach ($contest_users_from_scrape as $contest_user) {
                    $current_contest_entries = get_user_meta($contest_user->ID, 'contest_entries', true);
                    // Get the current meta value
                    $referral_id = get_user_meta($contest_user->ID, 'referral_id', true);
                    // Get the user's referral id
                    $current_contest_entries['sharing'][$social_network] += $referral_id_list[$referral_id];
                    // Credit the user for the number of new shares found
                    // Perform the meta update
                    update_usermeta($contest_user->ID, 'contest_entries', $current_contest_entries);
                    tdr_check_entry_cap($contest_user->ID, $campaign_slug);
                    // Check to see if entry cap is reached; Move to capped group if so
                    // DEBUG var_dump( $contest_user->ID );
                }
            }
            // DEBUG		var_dump( $contest_user_query );
            // DEBUG		var_dump( $contest_users_from_scrape );
            //$fp = fopen('/tmp/twitterscrape.txt', 'w');
            //fwrite($fp, $request_results);
            //fwrite($fp, var_dump( $user_list ) );
            //fclose($fp);
            // Write to /tmp
        }
    }
}