NAME
Twitter::API::Trait::ApiMethods - Convenient API Methods
VERSION
version 1.0006
DESCRIPTION
This trait provides convenient methods for calling API endpoints. They are Net::Twitter compatible, with the same names and calling conventions.
Refer to Twitter's API documentation for details about each method's parameters.
These methods are simply shorthand forms of get
and post
. All methods can be called with a parameters hashref. It can be omitted for endpoints that do not require any parameters, such as mentions
. For example, all of these calls are equivalent:
$client->mentions;
$client->mentions({});
$client->get('statuses/mentions_timeline');
$client->get('statuses/mentions_timeline', {});
Use the parameters hashref to pass optional parameters. For example,
$client->mentions({ count => 200, trim_user=>'true' });
Some methods, with required parameters, can take positional parameters. For example, geo_id
requires a place_id
parameter. These calls are equivalent:
$client->place_id($place);
$client->place_id({ place_id => $place });
When positional parameters are allowed, they must be specified in the correct order, but they don't all need to be specified. Those not specified positionally can be added to the parameters hashref. For example, these calls are equivalent:
$client->add_collection_entry($id, $tweet_id);
$client->add_collection_entry($id, { tweet_id => $tweet_id);
$client->add_collection_entry({ id => $id, tweet_id => $tweet_id });
Many calls require a screen_name
or user_id
. Where noted, you may pass either ID as the first positional parameter. Twitter::API will inspect the value. If it contains only digits, it will be considered a user_id
. Otherwise, it will be considered a screen_name
. Best practice is to explicitly declare the ID type by passing it in the parameters hashref, because it is possible to for users to set their screen names to a string of digits, making the inferred ID ambiguous. These calls are equivalent:
$client->create_block('realDonaldTrump');
$client->create_block({ screen_name => 'realDonaldTrump' });
Since all of these methods simple resolve to a get
or post
call, see the Twitter::API for details about return values and error handling.
METHODS
account_settings([ \%args ])
blocking([ \%args ])
Aliases: blocks_list
blocking_ids([ \%args ])
Aliases: blocks_ids
collection_entries([ $id, ][ \%args ])
collections([ $screen_name | $user_id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/curate-a-collection/api-reference/get-collections-list
favorites([ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-favorites-list
followers([ \%args ])
Aliases: followers_list
followers_ids([ $screen_name | $user_id, ][ \%args ])
friends([ \%args ])
Aliases: friends_list
friends_ids([ \%args ])
Aliases: following_ids
friendships_incoming([ \%args ])
Aliases: incoming_friendships
friendships_outgoing([ \%args ])
Aliases: outgoing_friendships
geo_id([ $place_id, ][ \%args ])
https://developer.twitter.com/en/docs/geo/place-information/api-reference/get-geo-id-place_id
geo_search([ \%args ])
https://developer.twitter.com/en/docs/geo/places-near-location/api-reference/get-geo-search
get_configuration([ \%args ])
get_languages([ \%args ])
get_list([ \%args ])
Aliases: show_list
get_lists([ \%args ])
Aliases: list_lists, all_subscriptions
get_privacy_policy([ \%args ])
get_tos([ \%args ])
home_timeline([ \%args ])
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline
list_members([ \%args ])
list_memberships([ \%args ])
list_ownerships([ \%args ])
list_statuses([ \%args ])
list_subscribers([ \%args ])
list_subscriptions([ \%args ])
Aliases: subscriptions
lookup_friendships([ \%args ])
lookup_statuses([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-lookup
lookup_users([ \%args ])
mentions([ \%args ])
Aliases: replies, mentions_timeline
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-mentions_timeline
mutes([ \%args ])
Aliases: muting_ids, muted_ids
muting([ \%args ])
Aliases: mutes_list
no_retweet_ids([ \%args ])
Aliases: no_retweets_ids
oembed([ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed
profile_banner([ \%args ])
rate_limit_status([ \%args ])
retweeters_ids([ $id, ][ \%args ])
retweets([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets-id
retweets_of_me([ \%args ])
Aliases: retweeted_of_me
reverse_geocode([ $lat, [ $long, ]][ \%args ])
https://developer.twitter.com/en/docs/geo/places-near-location/api-reference/get-geo-reverse_geocode
saved_searches([ \%args ])
search([ $q, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
sent_direct_messages([ \%args ])
Aliases: direct_messages_sent
show_friendship([ \%args ])
Aliases: show_relationship
show_list_member([ \%args ])
Aliases: is_list_member
show_list_subscriber([ \%args ])
Aliases: is_list_subscriber, is_subscriber_lists
show_saved_search([ $id, ][ \%args ])
show_status([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id
show_user([ $screen_name | $user_id, ][ \%args ])
suggestion_categories([ \%args ])
trends_available([ \%args ])
trends_closest([ \%args ])
trends_place([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/trends/trends-for-location/api-reference/get-trends-place
user_suggestions([ $slug, ][ \%args ])
user_suggestions_for([ $slug, ][ \%args ])
Aliases: follow_suggestions
user_timeline([ $screen_name | $user_id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline
users_search([ $q, ][ \%args ])
Aliases: find_people, search_users
verify_credentials([ \%args ])
add_collection_entry([ $id, [ $tweet_id, ]][ \%args ])
add_list_member([ \%args ])
create_block([ $screen_name | $user_id, ][ \%args ])
create_collection([ $name, ][ \%args ])
create_favorite([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-create
create_friend([ $screen_name | $user_id, ][ \%args ])
Aliases: follow, follow_new, create_friendship
create_list([ $name, ][ \%args ])
create_media_metadata([ \%args ])
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create
create_mute([ $screen_name | $user_id, ][ \%args ])
Alias: mute
create_saved_search([ $query, ][ \%args ])
curate_collection([ \%args ])
delete_list([ \%args ])
delete_list_member([ \%args ])
destroy_block([ $screen_name | $user_id, ][ \%args ])
destroy_collection([ $id, ][ \%args ])
destroy_favorite([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy
destroy_friend([ $screen_name | $user_id, ][ \%args ])
Aliases: unfollow, destroy_friendship
destroy_mute([ $screen_name | $user_id, ][ \%args ])
Alias: unmute
destroy_saved_search([ $id, ][ \%args ])
Aliases: delete_saved_search
destroy_status([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-destroy-id
members_create_all([ \%args ])
Aliases: add_list_members
members_destroy_all([ \%args ])
Aliases: remove_list_members
move_collection_entry([ $id, [ $tweet_id, [ $relative_to, ]]][ \%args ])
remove_collection_entry([ $id, [ $tweet_id, ]][ \%args ])
remove_profile_banner([ \%args ])
report_spam([ \%args ])
retweet([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-retweet-id
subscribe_list([ \%args ])
unretweet([ $id, ][ \%args ])
unsubscribe_list([ \%args ])
update([ $status, ][ \%args ])
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
update_account_settings([ \%args ])
update_collection([ $id, ][ \%args ])
update_friendship([ \%args ])
update_list([ \%args ])
update_profile([ \%args ])
update_profile_background_image([ \%args ])
update_profile_banner([ $banner, ][ \%args ])
update_profile_image([ $image, ][ \%args ])
upload_media([ $media, ][ \%args ])
Aliases: upload
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
direct_messages_events([ \%args ])
show_direct_messages_event([ $id, ][ \%args ])
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-event
destroy_direct_messages_event([ $id, ][ \%args ])
new_direct_messages_event([$text, $recipient_id ] | [ \%event ], [ \%args ])
For simple usage, pass text and recipient ID:
$client->new_dirrect_messages_event($text, $recipient_id)
For more complex messages, pass a full event structure, for example:
$client->new_direct_massages_event({
type => 'message_create',
message_create => {
target => { recipient_id => $user_id },
message_data => {
text => $text,
attachment => {
type => 'media',
media => { id => $media->{id} },
},
},
},
})
invalidate_access_token([ \%args ])
Calling this method has the same effect as a user revoking access to the application via Twitter settings. The access token/secret pair will no longer be valid.
This method can be called with client that has been initialized with access_token
and access_token_secret
attributes, by passing -token
and -token_secret
parameters, or by passing access_token
and access_token_secret
parameters.
$client->invalidate_access_token;
$client->invalidate_access_token({ -token => $token, -token_secret => $secret });
$client->invalidate_access_token({
access_token => $token,
access_token_secret => $secret,
});
Twitter added this method to the API on 2018-09-20.
See https://developer.twitter.com/en/docs/basics/authentication/api-reference/invalidate_access_token
AUTHOR
Marc Mims <marc@questright.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015-2021 by Marc Mims.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.