An open API service indexing awesome lists of open source software.

https://github.com/webdevstudios/wp_addthis_api_connect

Connect to the Addthis API using WordPress APIs
https://github.com/webdevstudios/wp_addthis_api_connect

Last synced: 8 months ago
JSON representation

Connect to the Addthis API using WordPress APIs

Awesome Lists containing this project

README

          

WP Addthis API Connect
======================

Connect to the [Addthis API](http://support.addthis.com/customer/portal/articles/381262-api-and-sdk-overview) using WordPress APIs

To get started, create a new WP_Addthis_API_Connect object by passing your username, password, pubid, and url (registered with Addthis).
```php
// Consumer credentials
$credentials = array(
'username' => 'justin@webdevstudios.com',
'password' => 'XXXXXXXXXXX',
'pubid' => 'ra-XXXXXXXXXXX',
'url' => 'webdevstudios.com',
);
$api = new WP_Addthis_API_Connect( $credentials );
```

You can then use this object to retrieve the authentication request URL, or if you have been authenticated, make requests.

```php
'justin@webdevstudios.com',
'password' => 'XXXXXXXXXXX',
'pubid' => 'ra-XXXXXXXXXXX',
'url' => 'webdevstudios.com',
);

$api = new WP_Addthis_API_Connect( $credentials );

$args = array(
'service' => 'twitter',
'domain' => 'webdevstudios.com',
'period' => 'last24',
'url' => 'http://webdevstudios.com/post-to-check',
);
// Get all twitter shares split into counts for every 10 minute increment
// in the last 24 hours.
$shares = $api->get_shares( 'url.json', $args );

if ( is_wp_error( $shares ) ) {

echo '

';
echo wpautop( $shares->get_error_message() );
echo '
';

} else {

$shares_count = 0;
foreach ( $shares as $share ) {
$shares_count = $shares_count + absint( $share->shares );
}

echo '


';
echo '

$shares_count: '. print_r( $shares_count, true ) .'';
echo '$shares: '. print_r( $shares, true ) .'';
echo '
';

}

}
add_action( 'all_admin_notices', 'wp_addthis_api_connect_example_test' );
```