php获取推特feed twitter timeline feed

1. https://apps.twitter.com/

申请 consumer_key, consumer_secret,oauth_access_token,oauth_access_token_secret

2. 下载项目:https://github.com/kmaida/twitter-timeline-php

下载:twitter-timeline-php-master

本人净化版:

require_once('_utils/twitter-api-oauth.php');

function formatTweet($tweet) 
{
    $linkified = '@(https?://([-w.]+[-w])+(:d+)?(/([w/_.#-]*(?S+)?[^.s])?)?)@';
    $hashified = '/(^|[ns])#([^s"tnr<:]*)/is';
    $mentionified = '/(^|[ns])@([^s"tnr<:]*)/is';
    
    $prettyTweet = preg_replace(
        array(
            $linkified,
            $hashified,
            $mentionified
        ), 
        array(
            '<a href="$1" class="link-tweet" target="_blank">$1</a>',
            '$1<a class="link-hashtag" href="https://twitter.com/search?q=%23$2&src=hash" target="_blank">#$2</a>',
            '$1<a class="link-mention" href="http://twitter.com/$2" target="_blank">@$2</a>'
        ), 
        $tweet
    );
    
    return $prettyTweet;
}
    
$settings = array(
    'consumer_key'              => "******",
    'consumer_secret'           => "******",
    'oauth_access_token'        => "******",
    'oauth_access_token_secret' => "******"
);

$tweetCount      = 3;
$twitterUsername = '';
$url             = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield        = '?screen_name=' . $twitterUsername . '&count=' . $tweetCount;

$twitter      = new TwitterAPITimeline($settings);
$json         = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
$twitter_data = json_decode($json, true);   // Create an array with the fetched JSON data

//echo '<pre>'; print_r($twitter_data) ;

$data = array();

foreach($twitter_data as $feed) 
{
    $photos = array();
    $media  = $feed['entities']['media'];
    if($media) foreach($media as $img) $photos[] = $img['media_url'];
    
    $data[] = array('tweet'=>formatTweet($feed['text']),'date'=>$feed['created_at'],'img'=>$photos);
}

echo '<pre>'; print_r($data);