Skip to content

SharedCount.com Support

Jared Atchison edited this page Jan 27, 2017 · 3 revisions

In the past, by default, EA Share Count pulled all of its share counts from SharedCount.com, a service that aggregated counts from all social services. This allowed us to do a single API call rather than one for each service.

Facebook then officially deprecated the API that SharedCount.com uses, which causes SharedCount.com to lose access Facebook counts.

When this happened, we made the decision to no longer use or rely the SharedCount service by default.

Starting at version 1.7.0 all counts are retrieved directly from the service and their respective API.

If you update from version <1.7.0 please note that no services will receive share counts until you configure it.

Go to Settings > Share Count to select which services you'd like to receive share counts for. Keep in mind each service is an additional API query, so it's recommended you only check those you and your users actually use to share your content.

Available share buttons are not tied to which services receive counts. In other words, you might only receive counts from Facebook, but display share buttons for Facebook, Twitter, Pinterest and Google+.

Restoring SharedCount.com

Beginning in 2017, SharedCount.com was able to once again track and report Facebook counts, once again making the service a viable option.

As of version 1.9 you extend the EA Share Count plugin to once again leverage the SharedCount.com API. This will condense API requests and improve performance.

See the code below.

<?php
/**
 * Disable the default request, except Twitter.
 *
 * This is so we can used the SharedCount API as that lets us make a single
 * request for most counts.
 *
 * @param array $services
 * @return array
 */
function easc_share_count_requests( $services ) {

	return array( 'twitter' => 'Twitter' );
}
add_filter( 'ea_share_count_query_requests', 'easc_share_count_requests' );

/**
 * Ping the ShareCount API for the counts.
 *
 * @param array $share_count
 * @param url $url
 * @return array
 */
function easc_share_count_query_api( $share_count, $args ) {

	$api_key      = 'YOURKEY';
	$api_query    = add_query_arg( array( 'url' => $args['url'], 'apikey' => $api_key ), 'https://free.sharedcount.com/url' );
	$api_response = wp_remote_get( $api_query, array( 'sslverify' => false ) );

	if ( ! is_wp_error( $api_response ) && 200 == wp_remote_retrieve_response_code( $api_response ) ) {

		$results = json_decode( wp_remote_retrieve_body( $api_response ), true );

		// Update counts
		$share_count['Facebook']['comment_count'] = !empty( $results['Facebook']['comment_count'] ) ? $results['Facebook']['comment_count'] : $share_count['Facebook']['comment_count'];
		$share_count['Facebook']['share_count']   = !empty( $results['Facebook']['share_count'] ) ? $results['Facebook']['share_count'] : $share_count['Facebook']['share_count'];
		$share_count['Facebook']['total_count']   = !empty( $results['Facebook']['total_count'] ) ? $results['Facebook']['total_count'] : $total_count['Facebook']['share_count'];
		$share_count['Pinterest']                 = !empty( $results['Pinterest'] ) ? $results['Pinterest'] : $share_count['Pinterest'];
		$share_count['StumbleUpon']               = !empty( $results['StumbleUpon'] ) ? $results['StumbleUpon'] : $share_count['StumbleUpon'];
		$share_count['LinkedIn']                  = !empty( $results['LinkedIn'] ) ? $results['LinkedIn'] : $share_count['LinkedIn'];
		$share_count['GooglePlusOne']             = !empty( $results['GooglePlusOne'] ) ? $results['GooglePlusOne'] : $share_count['GooglePlusOne'];
	}

	return $share_count;
}
add_filter( 'ea_share_count_query_api', 'easc_share_count_query_api', 10, 2 );
Clone this wiki locally