PHP Classes

File: examples/twitter.php

Recommend this page to a friend!
  Classes of Chun-Sheng, Li   PHP Social Network Sync   examples/twitter.php   Download  
File: examples/twitter.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Social Network Sync
Synchronize post feeds between social networks
Author: By
Last change:
Date: 7 months ago
Size: 1,246 bytes


Class file image Download
* The program is to post the Twitter feed via Twitter API.

require_once __DIR__.'/../vendor/autoload.php';

$apiKey = parse_ini_file(__DIR__.'/../api-key.ini');
$oauthToken = $apiKey['oauth_access_token'];
$oauthTokenSecret = $apiKey['oauth_access_token_secret'];
$consumerSecret = $apiKey['consumer_secret'];
$consumerKey = $apiKey['consumer_key'];

// Set access tokens here - see:
$settings = [
'oauth_access_token' => $oauthToken,
'oauth_access_token_secret' => $oauthTokenSecret,
'consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret

$message = "?????! @peter279k #hash_tag1";

// URL for REST request, see:
$url = '';
$requestMethod = 'POST';

// POST fields required by the URL above. See relevant docs as above
$postfields = [
'status' => $message,

// Perform the request and echo the response
$twitter = new TwitterAPIExchange($settings);
$buildOauth = $twitter->buildOauth($url, $requestMethod);

$result = json_decode($buildOauth->performRequest(), true);

$createdTime = $result['created_at'];