jacksleight/coast-social

Coast component for accessing social media APIs

0.2.3 2021-10-13 09:53 UTC

This package is auto-updated.

Last update: 2024-04-13 14:50:36 UTC


README

Packagist License

Coast Social can retrieve latest post feeds and URL statistics from various social media platforms in a standardised format. It is currently a work in progress, there are not yet any stable releases.

What's Supported?

⚫ = Supported, always present
⚪ = Supported, when present

Method Facebook Twitter Instagram Pinterest
feed
urlStats

feed

Input
Parameter Facebook Twitter Instagram Pinterest
id ⚫ (me)
username
limit ⚫ (10) ⚫ (10) ⚫ (10) ⚫ (10)
raw ⚫ ([]) ⚫ ([]) ⚫ ([]) ⚫ ([])
  • The raw parameter allows you to parse additional parameters to each providers API, refer to the relevant API documentation for more information.
Output
Attribute Facebook Twitter Instagram Pinterest
id
url
date
text
html
image.url
image.width
image.height
user.id
user.url
user.name
user.username
raw
  • The raw parameter contains the unmodified source from the API response.

urlStats

Input

A Coast\Url object.

Output
Stat Facebook Twitter Instagram Pinterest
shares
comments

Installation

The easiest way to install Coast Social is through Composer, by creating a file called composer.json containing:

{
    "require": {
        "jacksleight/coast-social": "dev-master"
    }
}

And then running:

composer.phar install

Usage

Facebook

$facebook = new Coast\Social\Provider\Facebook([
    'credentials' => [
        'appId'       => '',
        'appSecret'   => '',
        'accessToken' => '', // Get from https://developers.facebook.com/tools/explorer/
    ],
]);
$feed = $facebook->feed([
    'id'       => '', // User/page ID
    'username' => '', // User/page username
]);
$stats = $facebook->stats(new Coast\Url('http://www.example.com/'));

Twitter

$twitter = new Coast\Social\Provider\Twitter([
    'credentials' => [
        'consumerKey'       => '',
        'consumerSecret'    => '',
        'accessToken'       => '',
        'accessTokenSecret' => '',
    ],
]);
$feed = $twitter->feed([
    'username' => '',
]);

Instagram

$instagram = new Coast\Social\Provider\Instagram([
    'credentials' => [
        'accessToken' => '',
    ],
]);
$feed = $instagram->feed();

The Instagram provider uses the Instagram Basic Display API. Use the User Token Generator to generate an access token. The Instagram Basic Display API only allows access your own data. The input id parameter can be specified, but it is not required and will default to me;

Pinterest

$pinterest = new Coast\Social\Provider\Pinterest([
    'credentials' => [
        'appId'       => '',
        'appSecret'   => '',
        'accessToken' => '', // Get from https://developers.pinterest.com/tools/access_token/
    ],
]);
$feed = $pinterest->feed([
    'id'      => '', // Board ID
]);
$stats = $pinterest->stats(new Coast\Url('http://www.example.com/'));

Aggregate

$social = new Coast\Social([
    'providers' => [
        'twitter'  => $twitter,
        'facebook' => $facebook,
    ],
]);
$feed = $social->feed([ // Feeds from all providers
    'twitter'  => [
        'username' => '',
    ],
    'facebook' => [
        'id' => '',
    ],
]);
$feed = $social->feedFlat([ // Feeds from all providers merged and ordered by date
    'twitter'  => [
        'username' => '',
    ],
    'facebook' => [
        'id' => '',
    ],
]);
$stats = $social->stats(new Coast\Url('http://www.example.com/'));     // Stats from all providers
$stats = $social->statsFlat(new Coast\Url('http://www.example.com/')); // Stats from all providers added together

Licence

The MIT License

Copyright 2017 Jack Sleight http://jacksleight.com/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.