PHP Classes

PHP Social Network Sync: Synchronize post feeds between social networks

Recommend this page to a friend!
  Info   View files Example   View files View files (17)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 73 This week: 1All time: 10,197 This week: 560Up
Version License PHP version Categories
social-sync 1.0.0MIT/X Consortium ...5PHP 5, Web services, Social Networking
Description 

Author

This package can synchronize post feeds between social networks.

It can use a cloud email service to receive email messages from users that can post to certain social networks.

The cloud email service can receive the messages an process them to deliver to several social networks like Twitter and Facebook.

This is the simplest way to sync the feed for the multiple social websites.

Innovation Award
PHP Programming Innovation award winner
October 2022
Winner
Many sites post content to multiple social networks to get more exposure.

If a single content post needs to be done separately for each social network site, that takes a lot of time for the person posting the content to all the social networks.

This package provides a more automated solution that can take much less time for the person doing the work to post on social networks.

It requires sending a single email message with the content to post to the cloud email service. Then that service can process the content and distribute it to different social networks.

Manuel Lemos
Picture of Chun-Sheng, Li
  Performance   Level  
Name: Chun-Sheng, Li <contact>
Classes: 27 packages by
Country: Taiwan Taiwan
Age: 30
All time rank: 22646 in Taiwan Taiwan
Week rank: 411 Up2 in Taiwan Taiwan Up
Innovation award
Innovation award
Nominee: 13x

Winner: 1x

Example

<?php
/*
* This is the program to receive the mail via MailGun routes
*/

require_once __DIR__.'/src/autoloader.php';

use
peter\social\PostFeed;

header("Content-type: text/plain");

$mailGun = parse_ini_file(__DIR__.'/api-key.ini');
$apiKey = $mailGun['api_key'];
$sender = $mailGun['sender'];
$from = $mailGun['sandbox_address'];
$event = null;

if(
$_SERVER['REQUEST_METHOD'] == 'POST') {
   
$isSender = (isset($_POST['sender']) ? $_POST['sender']:'') === $sender;
   
$isFrom = (isset($_POST['recipient']) ? $_POST['recipient']:'') === $from;
    if(!
$isSender && !$isFrom) {
        echo
'The sender and from email address is invalid!';
        exit;
    }
} else {
    echo
'We do not accept this request method!';
    exit;
}

$bodyPlain = isset($_POST['body-plain']) ? $_POST['body-plain']:'';
$bodyPlain = str_replace('\r\n', PHP_EOL, $bodyPlain);

if(
$bodyPlain == '') {
    echo
'the message body is plain.';
    exit;
}

$iniList = parse_ini_string($bodyPlain, true);
$facebook = $iniList['facebook']['post'];
$twitter = $iniList['twitter']['post'];
$plurk = $iniList['plurk']['post'];
$message = $iniList['feed']['content'];
$link = $iniList['feed']['link'];

// parse the api-key.ini file to get the socail website credentials.
$apiKey = parse_ini_file('./api-key.ini', true);

// sync and post feed to Twitter, Facebook and Plurk.
$feed = new PostFeed();
$feed->setMessage($message);
$feed->setLink($link);

// Facebook
if($facebook === 'yes') {
   
$serviceName = 'Facebook';
    foreach(
$apiKey[$serviceName] as $key => $value) {
       
$feed->setSettings($key, $value);
    }
   
$feed->setServiceName($serviceName);
   
$feed->postFeed();
   
$httpCode = $feed->getHttpStatusCode();
   
$responseMsg = $feed->getResponseMessage();
}

// Twitter
if($twitter === 'yes') {
   
$serviceName = 'Twitter';
    foreach(
$apiKey[$serviceName] as $key => $value) {
       
$feed->setSettings($key, $value);
    }
   
$feed->setServiceName($serviceName);
   
$feed->postFeed();
   
$httpCode = $feed->getHttpStatusCode();
   
$responseMsg = $feed->getResponseMessage();
}

// Plurk
if($plurk === 'yes') {
   
$serviceName = 'Plurk';
    foreach(
$apiKey[$serviceName] as $key => $value) {
       
$feed->setSettings($key, $value);
    }
   
$feed->setServiceName($serviceName);
   
$feed->postFeed();
   
$httpCode = $feed->getHttpStatusCode();
   
$responseMsg = $feed->getResponseMessage();
}


Details

social-sync

This is the simplest way to sync the feed for the multiple social websites.

social website lists

Scenairo

  • using the e-mail client to send the mail to the cloudmailin address.
  • The web service is to receive the mail and process the contents.
  • The web service will post the feed to the specified social websites after checking the mail content is successful.

Request the Facebook and Twitter developer APP

Usage

  • Set the cloudmailin service.
  • Set the ```receive.php``` to the receiving mail endpoint.
  • Visit the ```facebook_user_token.php``` from web browser to get the short-lived user access token and add it in ```api-key.ini```.
  • Refer this link to get the long-lived token.
  • Remember that the Facebook user access token is valid for 60 days.After 60 days, you have to request the new access token from ```facebook_user_token.php```.
  • In order to build the service easily, we use the Composer to manage the required packages.
  • Firstly, clone the repo: ``` git clone https://github.com/peter279k/social-sync.git```.
  • Then download the composer.phar: ```curl -sS https://getcomposer.org/installer | php```.
  • Then install the required packages: ```php composer.phar install```.
  • Create the ```api-key.ini``` in this project root path.
[Facebook]
app_id="facebook_id"
app_secret="facebook_secret"
user_access_token="facebook_user_token"
[Twitter]
api_key="api_key"
[Plurk]
user_name="user_name"
user_password="password"
user_id="user_id"

  • Complete the service building. Have fun!
  • P.S: The PHP program in ```examples``` folder just present the posting feed examples.
  • The socail api lists references

> - Twitter API reference > - Facebook API reference > - Plurk Bot sample code


  Files folder image Files  
File Role Description
Files folder imageexamples (5 files)
Files folder imagesrc (1 file, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file receive.php Example Example script

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file facebook.php Example Example script
  Accessible without login Plain text file facebook_post.php Example Example script
  Accessible without login Plain text file fb_callback.php Example Example script
  Accessible without login Plain text file plurk.php Aux. Auxiliary script
  Accessible without login Plain text file twitter.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imagepeter (1 directory)
  Accessible without login Plain text file autoloader.php Aux. Auxiliary script

  Files folder image Files  /  src  /  peter  
File Role Description
Files folder imagesocial (5 files)

  Files folder image Files  /  src  /  peter  /  social  
File Role Description
  Plain text file Facebook.php Class Class source
  Plain text file Plurk.php Class Class source
  Plain text file PostFeed.php Class Class source
  Plain text file SocialInterface.php Class Class source
  Plain text file Twitter.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:73
This week:1
All time:10,197
This week:560Up