Hi Daniel, thanks for asking!
So you want to load Tweets from a certain user into your website? Sounds cool.
As Andy already stated, it might be the easiest to try out one of the pre-made widgets. They take care of displaying the Tweets appropriately (confirming the Display Requirements etc.), so this will be the least-effort way for you.
Once you’ve read the docs and are still convinced you’d like to go the manual way, get yourself an App with read-only access at https://apps.twitter.com. You’ll end up with an OAuth consumer key (it represents the app) and a secret (that you should keep secret). Then, open the App editing page (click your App name on apps.twitter.com) and generate an OAuth token for yourself. This will be the easiest way of accessing your own Tweets without going through the authentication flow.
Next, you’d want to download a copy of a Twitter library for PHP. For this sample, I’ll use Codebird-PHP, but it should be similar with any other library.
Then, include the library in your script and have it fetch what you want to access:
// you will get all of these at apps.twitter.com
define('TWITTER_OAUTH_CONSUMER_KEY', 'YourSecretKeyHere');
define('TWITTER_OAUTH_CONSUMER_SECRET', 'YourSecretSecretHere');
define('TWITTER_OAUTH_TOKEN', '12345-SomeVeryLongTokenWithADashInside');
define('TWITTER_OAUTH_TOKEN_SECRET', 'OneSecretMore');
// include the library, PHP 5.5+ required!
require_once 'libraries/codebird/src/codebird.php';
// make it aware of your OAuth app key
\Codebird\Codebird::setConsumerKey(
TWITTER_OAUTH_CONSUMER_KEY,
TWITTER_OAUTH_CONSUMER_SECRET
);
// now get an instance of the class
$cb = \Codebird\Codebird::getInstance();
// tell the library who you are
$cb->setToken(
TWITTER_OAUTH_TOKEN,
TWITTER_OAUTH_TOKEN_SECRET
);
// scroll down to read the rest of this sample code
// set the user name to fetch tweets for
define('TWITTER_TIMELINE_USER', 'LarryMcTweet'); // without the @ sign
// load the tweets
$reply = $cb->statuses_userTimeline([
'screen_name' => TWITTER_TIMELINE_USER
]);
// check if reply was okay
if ($reply->httpstatus === 200) { // HTTP 200 is OK
// forget the httpstatus and rate limiting fields
unset($reply->httpstatus);
unset($reply->rate);
// all the tweets are in the reply now
foreach ($reply as $tweet) {
echo $tweet->text;
}
}
When you want to find out what fields are included in a Tweet, check out the Tweet object reference.
Now, take into account how many users are visiting your website. Take a look at the rate-limiting section of the developer docs. Then, decide if you want to cache the Twitter API response for like 5 or 15 minutes so you won’t run over your limit.