A while ago I wrote a post explaining how to pull data from Twitter's API. I focused on pulling the default authenticated user timeline (which, if you set up the application under your account, you are the authenticated user). Wouldn't it be great if you could customize the request a bit?
The default feed will have the most recent 20 tweets from you. If you want to pull a different user or a different amount of tweets you'll have to pass in some parameters with your request. Note: protected timelines can only be pulled by the owner or their followers. There are two parameters that we'll need to use… screen_name and count.
Building off my first post, to pass in additional paramters you'll need to change a few lines in the OAuth Signature.
$oauth_hash = '';
$oauth_hash .= 'count=TOTAL_COUNT_YOU_WANT&';
$oauth_hash .= 'oauth_consumer_key=YOUR_CONSUMER_KEY&';
$oauth_hash .= 'oauth_nonce=' . time() . '&';
$oauth_hash .= 'oauth_signature_method=HMAC-SHA1&';
$oauth_hash .= 'oauth_timestamp=' . time() . '&';
$oauth_hash .= 'oauth_token=YOUR_ACCESS_TOKEN&';
$oauth_hash .= 'oauth_version=1.0&';
$oauth_hash .= 'screen_name=SCREEN_NAME_HERE';
Another change you need to make is with the OAuth header, again adding the two new parameters.
$oauth_header = '';
$oauth_header .= 'count="TOTAL_COUNT_YOU_WANT", ';
$oauth_header .= 'oauth_consumer_key="YOUR_CONSUMER_KEY", ';
$oauth_header .= 'oauth_nonce="' . time() . '", ';
$oauth_header .= 'oauth_signature="' . $signature . '", ';
$oauth_header .= 'oauth_signature_method="HMAC-SHA1", ';
$oauth_header .= 'oauth_timestamp="' . time() . '", ';
$oauth_header .= 'oauth_token="YOUR_ACCESS_TOKEN", ';
$oauth_header .= 'oauth_version="1.0", ';
$oauth_header .= 'screen_name="SCREEN_NAME_HERE"';
The last change is with the curl url itself.
curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=TOTAL_COUNT_YOU_WANT&screen_name=SCREEN_NAME_HERE');
There are other parameters you could pass in as well, including exclude_replies, max_id, and more. You would just follow the same changes for each new field. When I was testing this I noticed that Twitter seemed to want the parameters in alphabetical order - not sure if that was a temp issue or is still the case, but it's not hard to set things up that way. To see the other parameters, check out Twitter's documentation on user_timeline.