Twitter Class
MeNeedz's Twitter Class provides easy access to the Twitter API:
Setting Twitter Preferences
There are 2 ways to set the preferences need to run the Twitter library:
Set the preferences by passing a config array to the init function
$config['username'] = 'username';
$config['password'] = 'password';
$this->twitter->init($config);
Setting Twitter Preferences in a Config File
If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the twitter.php, add the $config array in that file. Then save the file at config/twitter.php and it will be used automatically. You will NOT need to use the $this->twitter->init() function if you save your preferences in a config file.
Twitter Preferences
The following is a list of all the preferences that can be set when using Akismet spam protection.
| Preference | Default Value | Options | Description |
|---|---|---|---|
| username | NULL | String value | Username for login into Twitter. |
| password | NULL | String value | Password for login into Twitter |
Twitter Function Reference
$this->twitter->account_verify_credentials()
Verifies the given credentials:
if($this->twitter->account_verify_credentials())
{
echo 'valid';
}
else
{
echo 'invalid';
}
Returns TRUE if your credentials are OK, FALSE if they are not.
$this->twitter->statuses_home_timeline()
Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.
$this->twitter->statuses_user_timeline()
Returns the 20 most recent statuses posted from the authenticating user. It's also possible to request another user's timeline via the user_id parameter.
$this->twitter->statuses_user_timeline(); // returns 20 most recent statuses posted by the authenticated user
$this->twitter->statuses_user_timeline(12345); // returns 20 most recent statuses posted by user 12345
$this->twitter->statuses_user_timeline('bob'); // returns 20 most recent statuses posted by user bob
$this->twitter->statuses_update()
Updates the authenticating user's status. Requires the status parameter specified below.
$status = 'Playing with the new Twitter library for CI!';
$this->twitter->statuses_update($status);
$this->twitter->statuses_public_timeline()
Returns the 20 most recent statuses from non-protected users who have set a custom user icon.
$this->twitter->statuses_public_timeline();
$this->twitter->request()
Sends the request to Twitter and returns the response after parsing it. You can use this to send your own API calls.
Have a look at the Twitter API documentation for all available methods.
$this->twitter->request('GET', 'statuses/friends', TRUE, array('id' => 12345), 'xml'); // This would call the API method statues friends and return all friends of friend 12345 in xml format.
// The available formats of the response for each API method can be found in the documentation. If the format is json the responsed is automatically parsed, for others you will get the raw data and will have to do the parsing yourself.