All Projects → dg → Twitter Php

dg / Twitter Php

Licence: bsd-3-clause
Small and easy PHP library for sending messages to Twitter and receiving statuses.

Projects that are alternatives of or similar to Twitter Php

Twitteroauth
The most popular PHP library for use with the Twitter OAuth REST API.
Stars: ✭ 4,134 (+715.38%)
Mutual labels:  twitter-api, twitter
Coretweet
Yet Another .NET Twitter Library
Stars: ✭ 281 (-44.58%)
Mutual labels:  twitter-api, twitter
markdown-tweet-scheduler
Schedule daily tweets from markdown files in your repo, posted via github actions.
Stars: ✭ 49 (-90.34%)
Mutual labels:  twitter, twitter-api
twitter-stream-api
Consume the Twitter Stream API in real-time.
Stars: ✭ 19 (-96.25%)
Mutual labels:  twitter, twitter-api
Mastodon Twitter Poster
Crossposter to post statuses between Mastodon and Twitter
Stars: ✭ 317 (-37.48%)
Mutual labels:  twitter-api, twitter
TwitterPiBot
A Python based bot for Raspberry Pi that grabs tweets with a specific hashtag and reads them out loud.
Stars: ✭ 85 (-83.23%)
Mutual labels:  twitter, twitter-api
Twitter Scraper
Scrape the Twitter Frontend API without authentication.
Stars: ✭ 3,037 (+499.01%)
Mutual labels:  twitter-api, twitter
bird-elephant
PHP client library for Twitter API v2 endpoints.
Stars: ✭ 28 (-94.48%)
Mutual labels:  twitter, twitter-api
Tweetie
Simple jQuery Twitter feed plugin
Stars: ✭ 314 (-38.07%)
Mutual labels:  twitter-api, twitter
Twitter Api V2 Sample Code
Sample code for the Twitter API early access endpoints (Python, Java, Ruby, and Node.js).
Stars: ✭ 306 (-39.64%)
Mutual labels:  twitter-api, twitter
Twitter Sort
🐦 Sort numbers with some help from the Twitter API
Stars: ✭ 384 (-24.26%)
Mutual labels:  twitter-api, twitter
Linqtotwitter
LINQ Provider for the Twitter API (C# Twitter Library)
Stars: ✭ 401 (-20.91%)
Mutual labels:  twitter-api, twitter
Archive-Tweets
Archive and Delete Liked and Posted Tweets
Stars: ✭ 28 (-94.48%)
Mutual labels:  twitter, twitter-api
Search Tweets Python
Python client for the Twitter search endpoints (v2/Labs/premium/enterprise). Now supports Twitter API v2 /recent and /all search endpoints.
Stars: ✭ 378 (-25.44%)
Mutual labels:  twitter-api, twitter
shut-up-bird
🐦 Put your tweets/likes in an EPUB and delete them like a boss
Stars: ✭ 22 (-95.66%)
Mutual labels:  twitter, twitter-api
archive-explorer-web
Browse your Twitter archive with a friendly, responsive, full experience, and quickly delete the tweets you don't want.
Stars: ✭ 19 (-96.25%)
Mutual labels:  twitter, twitter-api
Egg Mode
a twitter api crate for rust
Stars: ✭ 249 (-50.89%)
Mutual labels:  twitter-api, twitter
labs-sample-code
Sample code for Twitter Developer Labs
Stars: ✭ 25 (-95.07%)
Mutual labels:  twitter, twitter-api
Surfbird
A Microblogging client built on Electron and Vue
Stars: ✭ 309 (-39.05%)
Mutual labels:  twitter-api, twitter
Advertools
advertools - online marketing productivity and analysis tools
Stars: ✭ 341 (-32.74%)
Mutual labels:  twitter-api, twitter

Twitter for PHP Buy me a coffee

Downloads this Month

Twitter for PHP is a very small and easy-to-use library for sending messages to Twitter and receiving status updates.

It requires PHP 5.4 or newer with CURL extension and is licensed under the New BSD License. You can obtain the latest version from our GitHub repository or install it via Composer:

composer require dg/twitter-php

Support Me

Do you like Nette DI? Are you looking forward to the new features?

Buy me a coffee

Thank you!

Usage

Sign in to the https://twitter.com and register an application from the https://apps.twitter.com page. Remember to never reveal your consumer secrets. Click on My Access Token link from the sidebar and retrieve your own access token. Now you have consumer key, consumer secret, access token and access token secret.

Create object using application and request/access keys

use DG\Twitter\Twitter;

$twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);

The send() method updates your status. The message must be encoded in UTF-8:

$twitter->send('I am fine today.');

The load() method returns the 20 most recent status updates posted by you:

$statuses = $twitter->load(Twitter::ME);

or posted by you and your friends:

$statuses = $twitter->load(Twitter::ME_AND_FRIENDS);

or most recent mentions for you:

$statuses = $twitter->load(Twitter::REPLIES);

Extracting the information from the channel is easy:

foreach ($statuses as $status) {
	echo "message: ", Twitter::clickable($status);
	echo "posted at " , $status->created_at;
	echo "posted by " , $status->user->name;
}

The static method Twitter::clickable() makes links, mentions and hash tags in status clickable.

The authenticate() method tests if user credentials are valid:

if (!$twitter->authenticate()) {
	die('Invalid name or password');
}

The search() method provides searching in twitter statuses:

$results = $twitter->search('#nette');

The returned result is a again array of statuses.

Error handling

All methods throw a DG\Twitter\Exception on error:

try {
	$statuses = $twitter->load(Twitter::ME);
} catch (DG\Twitter\Exception $e) {
	echo "Error: ", $e->getMessage();
}

Additional features

The authenticate() method tests if user credentials are valid:

if (!$twitter->authenticate()) {
	die('Invalid name or password');
}

Other commands

You can use all commands defined by Twitter API 1.1. For example GET statuses/retweets_of_me returns the array of most recent tweets authored by the authenticating user:

$statuses = $twitter->request('statuses/retweets_of_me', 'GET', ['count' => 20]);

Changelog

v4.1 (11/2019)

  • added Delete Method (#68)
  • token is optional throughout + supply get() method

v4.0 (2/2019)

  • requires PHP 7.1 and uses its advantages like typehints, strict types etc.
  • class Twitter is now DG\Twitter\Twitter
  • class TwitterException is now DG\Twitter\Exception

v3.8 (2/2019)

  • Twitter::sendDirectMessage() uses new API
  • Twitter::clickable: added support for $status->full_text (#60)

v3.7 (3/2018)

  • minimal required PHP version changed to 5.4
  • Twitter::send() added $options
  • Twitter::clickable() now works only with statuses and entites
  • fixed coding style

v3.6 (8/2016)

  • added loadUserFollowersList() and sendDirectMessage()
  • Twitter::send() allows to upload multiple images
  • changed http:// to https://

v3.5 (12/2014)

  • allows to send message starting with @ and upload file at the same time in PHP >= 5.5

v3.4 (11/2014)

  • cache expiration can be specified as string
  • fixed some bugs

v3.3 (3/2014)

  • Twitter::send($status, $image) can upload image
  • added Twitter::follow()

v3.2 (1/2014)

  • Twitter API uses SSL OAuth
  • Twitter::clickable() supports media
  • added Twitter::loadUserInfoById() and loadUserFollowers()
  • fixed Twitter::destroy()

v3.1 (3/2013)

  • Twitter::load() - added third argument $data
  • Twitter::clickable() uses entities; pass as parameter status object, not just text
  • added Twitter::$httpOptions for custom cURL configuration

v3.0 (12/2012)

  • updated to Twitter API 1.1. Some stuff deprecated by Twitter was removed:
    • removed RSS, ATOM and XML support
    • removed Twitter::ALL
    • Twitter::load() - removed third argument $page
    • Twitter::search() requires authentication and returns different structure
  • removed shortening URL using http://is.gd
  • changed order of Twitter::request() arguments to $resource, $method, $data

v2.0 (8/2012)

  • added support for OAuth authentication protocol
  • added Twitter::clickable() which makes links, @usernames and #hashtags clickable
  • installable via composer require dg/twitter-php

v1.0 (7/2008)

  • initial release

(c) David Grudl, 2008, 2016 (https://davidgrudl.com)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].