This package is abandoned and will receive no further development!
See the Technical Steering Committee meeting minutes
ΠΡ, ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΈ Laminas, ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² ΡΠ°Π·Π½ΡΡ ΡΡΡΠ°Π½Π°Ρ . Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΠΊΠΈ ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² Π ΠΎΡΡΠΈΠΈ, ΡΠ°ΠΊ ΠΈ Π² Π£ΠΊΡΠ°ΠΈΠ½Π΅. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² Π ΠΎΡΡΠΈΠΈ. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΠΆΠΈΠ²ΡΡ Π² Π ΠΎΡΡΠΈΠΈ. Π£ Π½Π΅ΠΊΠΎΡΠΎΡΡΡ Π±Π°Π±ΡΡΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡΡΠΊΠΈ ΡΡΠ°ΠΆΠ°Π»ΠΈΡΡ Ρ ΡΠ°ΡΠΈΡΡΠ°ΠΌΠΈ Π²ΠΎ ΠΡΠΎΡΠΎΠΉ ΠΌΠΈΡΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. ΠΠ΄Π΅ΡΡ Π½ΠΈΠΊΡΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΠΈΠ·ΠΌ.
Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠ°Ρ ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΡΠ°, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΏΠ°ΡΠ»Π°ΡΡ ΠΈΠ· Π΄ΠΎΠΌΠ° Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΡΠ½ΠΎΠΌ. ΠΠΎΠ΅Π·Π΄ Π·Π°Π΄Π΅ΡΠΆΠ°Π»ΡΡ ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡΠΎΠ³Π΅ Π²ΠΏΠ΅ΡΠ΅Π΄ΠΈ. Π£ Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΏΡΡΡΡΡΡΡ Π² Π±ΠΎΠΌΠ±ΠΎΡΠ±Π΅ΠΆΠΈΡΠ°Ρ . ΠΡ Ρ ΡΡΠ΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ Π²Π΅ΡΡΠΎΡΠΊΠΈ ΠΎΡ Π½ΠΈΡ ΠΏΠΎΡΠ»Π΅ Π²ΠΎΠ·Π΄ΡΡΠ½ΡΡ Π½Π°Π»Π΅ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±Π΅ΡΠΏΠΎΡΡΠ΄ΠΎΡΠ½ΠΎ Π½Π°Π½ΠΎΡΡΡ ΡΠ΄Π°ΡΡ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡΡ ΠΏΠΎ Π±ΠΎΠ»ΡΠ½ΠΈΡΠ°ΠΌ, ΡΠΊΠΎΠ»Π°ΠΌ, Π΄Π΅ΡΡΠΊΠΈΠΌ ΡΠ°Π΄Π°ΠΌ ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠΡ Π½Π΅ Π±Π΅ΡΠ΅ΠΌ ΡΡΠΎ ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ -Π»ΠΈΠ±ΠΎ Π‘ΠΠ. ΠΡ Π½Π°Π±Π»ΡΠ΄Π°Π΅ΠΌ ΡΡΠΎ Π½Π°ΠΏΡΡΠΌΡΡ.
ΠΡ Π΄ΠΎΠ²Π΅ΡΡΠ΅ΡΠ΅ Π½Π°ΠΌ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ, ΡΡΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΈ ΠΌΡ ΠΏΡΠΎΡΠΈΠΌ Π²Π°Ρ Π΄ΠΎΠ²Π΅ΡΠΈΡΡΡΡ Π½Π°ΠΌ Π²Π½ΠΎΠ²Ρ. ΠΡ Π½ΡΠΆΠ΄Π°Π΅ΠΌΡΡ Π² ΠΏΠΎΠΌΠΎΡΠΈ. ΠΡΡ ΠΎΠ΄ΠΈΡΠ΅ ΠΈ ΠΏΡΠΎΡΠ΅ΡΡΡΠΉΡΠ΅ ΠΏΡΠΎΡΠΈΠ² ΡΡΠΎΠΉ Π±Π΅ΡΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ Π²ΠΎΠΉΠ½Ρ. ΠΡΡΠ°Π½ΠΎΠ²ΠΈΡΠ΅ ΠΊΡΠΎΠ²ΠΎΠΏΡΠΎΠ»ΠΈΡΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡΠ΅ "ΠΠ΅Ρ Π²ΠΎΠΉΠ½Π΅!"
We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
Provides an object oriented PHP wrapper for the Twitter API.
Run the following to install this library:
$ composer require laminas/laminas-twitter
Instantiate the Twitter
class by providing your Twitter consumer key and
secret, as well as the access token and secret:
use Laminas\Twitter\Twitter;
$twitter = new Twitter([
'access_token' => [
'token' => '<token value>',
'secret' => '<token secret value>',
],
'oauth_options' => [
'consumerKey' => '<consumer key value>',
'consumerSecret' => '<consumer secret value>',
],
]);
Once you have done that, you may start making calls to the API. This can be done in one of three ways:
- Using direct method calls on the
Twitter
class. A full list is provided below. - Using the "proxy" functionality. In these cases, you will provide the first
path element of the API, and then call a method on it:
$twitter->statuses->update($message)
. - Using the
get()
orpost()
methods.
accountVerifyCredentials() : Response
applicationRateLimitStatus() : Response
blocksCreate($id) : Response
blocksDestroy($id) : Response
blocksIds(int $cursor = -1) : Response
blocksList(int $cursor = -1) : Response
directMessagesDestroy($id) : Response
directMessagesMessages(array $options = []) : Response
directMessagesNew($user, string $text, array $extraParams = []) : Response
directMessagesEventsNew($user, string $text, array $extraParams = []) : Response
directMessagesSent(array $options = []) : Response
favoritesCreate($id) : Response
favoritesDestroy($id) : Response
favoritesList(array $options = []) : Response
followersIds($id, array $params = []) : Response
friendsIds($id, array $params = []) : Response
friendshipsCreate($id, array $params = []) : Response
friendshipsLookup($id, array $params = []) : Response
friendshipsDestroy($id) : Response
listsMembers($listIdOrSlug, array $params = []) : Response
listsMemberships($id, array $params = []) : Response
listsSubscribers($id, array $params = []) : Response
searchTweets(string $query, array $options = []) : Response
statusesDestroy($id) : Response
statusesHomeTimeline(array $options = []) : Response
statusesMentionsTimeline(array $options = []) : Response
statusesSample() : Response
statusesShow($id, array $options = []) : Response
statusesUpdate(string $status, $inReplyToStatusId = null, $extraAttributes = []) : Response
statusesUserTimeline(array $options = []) : Response
usersLookup($id, array $params = []) : Response
usersSearch(string $query, array $options = []) : Response
usersShow($id) : Response
The following proxy properties are allowed:
- account
- application
- blocks
- directmessages
- favorites
- followers
- friends
- friendships
- lists
- search
- statuses
- users
In each case, you can identify available methods for the proxy by comparing the
proxy name to the above list of methods. As an example, the users
proxy allows
the following:
$twitter->users->lookup($id, array $params = []);
$twitter->users->search(string $query, array $options = []);
$twitter->users->show($id);
The Twitter API has dozens of endpoints, some more popular and/or useful than others. As such, we are only providing a subset of what is available.
However, we allow you to access any endpoint via either the get()
or post()
methods, which have the following signatures:
public function get(string $path, array $query = []) : Response;
public function post(string $path, $data = null) : Response;
In each case, the $path
is the API endpoint as detailed in the Twitter API
documentation, minus any .json
suffix, and the method name corresponds to
whether the request happens via HTTP GET or POST.
For HTTP GET requests, the $query
argument provides any query string
parameters you want to pass for that endpoint. As an example, if you were
requesting statuses/home_timeline
, you might pass count
or since_id
.
For HTTP POST requests, the $data
argument can be one of:
- An associative array of data.
- A serializable object of data.
- A string representing the raw payload.
The data to provide will vary based on the endpoint.
Since version 3.0, we have supported media uploads via the classes
Laminas\Twitter\Media
, Image
, and Video
. In each case, you will
instantiate the appropriate class with the local filesystem path of the image to
upload and the media type, followed by calling upload()
with a properly
configured HTTP client. The response will contain a media_id
property, which
you can then provide via the media_ids
parameter when posting a status:
$image = new Image('data/logo.png', 'image/png');
$response = $image->upload($twitter->getHttpClient());
$twitter->statusUpdate(
'A post with an image',
null,
['media_ids' => [$response->media_id]]
);
When providing media for direct messages, you must provide additional flags to the media class's constructor:
- A flag indicating it is for a direct message
- A flag indicating whether or not the uploaded media may be shared/re-used in other direct messages.
$image = new Image(
'data/logo.png',
'image/png',
$forDirectMessage = true,
$shared = false
);
$upload = $image->upload($twitter->getHttpClient());
Unlike non-DM media uploads, the identifier will be in the id_str
parameter of
the returned upload instance; use that as a media_id
in your DM:
$twitter->directmessagesEventsNew(
$user,
$message,
['media_id' => $upload->id_str]
);
Note: direct messages only support a single attachment.
As of version 3.0, we now provide introspection of Twitter's rate limit headers, allowing you to act on them:
$response = $twitter->statusUpdate('A post');
$rateLimit = $response->getRateLimit();
if ($rateLimit->remaining === 0) {
// Time to back off!
sleep($rateLimit->reset); // seconds left until reset
}