Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Log1x/socialproof
A fluent interface for retrieving follower counts from social API's.
https://github.com/Log1x/socialproof
fluent followers php social social-api
Last synced: about 2 months ago
JSON representation
A fluent interface for retrieving follower counts from social API's.
- Host: GitHub
- URL: https://github.com/Log1x/socialproof
- Owner: Log1x
- License: mit
- Archived: true
- Created: 2018-07-25T10:37:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-08T13:01:03.000Z (over 5 years ago)
- Last Synced: 2024-07-31T01:46:26.998Z (about 2 months ago)
- Topics: fluent, followers, php, social, social-api
- Language: PHP
- Size: 13.7 KB
- Stars: 39
- Watchers: 7
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SocialProof
[![Latest Stable Version](https://poser.pugx.org/log1x/socialproof/v/stable)](https://packagist.org/packages/log1x/socialproof) [![Total Downloads](https://poser.pugx.org/log1x/socialproof/downloads)](https://packagist.org/packages/log1x/socialproof)
## What is SocialProof?
SocialProof is a [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface) for fetching followers / fans from various social media platforms using their internal API. It handles all API requests asynchronous using [Guzzle](https://github.com/guzzle/guzzle) and catches API exceptions / errors with a user-definable default value.
## Features
* Simple, fluent syntax for handling credentials / configuration.
* Completely asynchronous using Guzzle's `getAsync()`.
* User-definable default values when an API request fails.
* Simple debugging when configuring.
* Automatically handles OAuth when fetching from API's such as Twitter.
* Easily extendable and all PR's are very welcome. :heart:## Current Platforms
* [Facebook](https://developers.facebook.com/)
* [Twitter](https://developer.twitter.com/)
* [Instagram](https://www.instagram.com/developer/)
* [Pinterest](https://developers.pinterest.com/)
* [LinkedIn](https://developer.linkedin.com/)All pull requests for additional platforms are greatly appreciated. Please use the existing [Providers](https://github.com/Log1x/socialproof/tree/master/src/Providers) as an example.
## Requirements
* [PHP](https://secure.php.net/manual/en/install.php) >= 7.0
* [Composer](https://getcomposer.org/download/)## Installation
Install via Composer:
```bash
composer require log1x/socialproof
```## Usage
SocialProof is incredibly easy to use, but caching values and storing them appropriately to not hit API limits / affect performance is up to the end-user. For WordPress, an example would be using the [Transients API](https://codex.wordpress.org/Transients_API) with an expiration of every 24 hours and the [Options API](https://codex.wordpress.org/Options_API) for a fallback value along with `->setDefault()` in the event an API request fails after your transient expires.
```php
use SocialProof\SocialProof;return SocialProof::social()
->facebook()
->setUsername('example')
->setToken('XXXXXXXXXXXXXXXXXXXXXXXX')
->get();
```See [here](http://tools.creoworx.com/facebook/) to generate a token for Facebook.
```php
use SocialProof\SocialProof;return SocialProof::social()
->twitter()
->setUsername('username')
->setConsumerKey('XXXXXXXXXXXXXXXXXXXXXXXX')
->setConsumerSecret('XXXXXXXXXXXXXXXXXXXXXXXX')
->setToken('XXXXXXXXXXXXXXXXXXXXXXXX')
->setTokenSecret('XXXXXXXXXXXXXXXXXXXXXXXX')
->get();
``````php
use SocialProof\SocialProof;return SocialProof::social()
->instagram()
->setToken('XXXXXXXXXXXXXXXXXXXXXXXX')
->get();
``````php
use SocialProof\SocialProof;return SocialProof::social()
->pinterest()
->setUsername('username')
->get();
``````php
use SocialProof\SocialProof;return SocialProof::social()
->linkedin()
->setUsername('username')
->setToken('XXXXXXXXXXXXXXXXXXXXXXXX')
->get();
```## Configuration
`SocialProof::social()` accepts various configuration when passing through your social credentials. Here's an example using Facebook:
```php
use SocialProof\SocialProof;return SocialProof::social()
->facebook()
->setUsername('example')
->setToken('XXXXXXXXXXXXXXXXXXXXXXXX')
->setDefault('No followers')
->setApi('https://graph.facebook.com')
->setEndpoint('/v2.7/')
->setTimeout(60)
->setDebug()
->get();
```A long form syntax is also available for passing credentials and configuration through an array using `setCredentials($array)` and `setConfigs($array)` or a string using `setCredential($key, $value)` and `setConfig($key, value)`.
```php
use SocialProof\SocialProof;return SocialProof::social()
->facebook()
->setCredentials([
'username' => 'example',
'token' => 'XXXXXXXXXXXXXXXXXXXXXXXX'
])
->setConfig('default', 'No Followers')
->get();
```## Debugging
Since SocialProof catches API errors, timeouts, etc. and returns a default value instead, you can use `->setDebug()` to enable debugging during initial setup.