phpツイッターfeed twitter timeline feedを取得

3205 ワード

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 = '/(^|[
\s])#([^\s"\t
\r<:]*)/is'; $mentionified = '/(^|[
\s])@([^\s"\t
\r<:]*)/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);

 
justcode.ikeepstudying.com