Python API¶
Twitter¶
-
class
RPA.Twitter.Tweet(created_at: datetime.datetime, id: int, tweet_id_str: str, text: str, in_reply_to_screen_name: str, lang: str, name: str, screen_name: str, hashtags: list, is_truncated: bool = False, favorite_count: int = 0, retweeted: bool = False, retweet_count: int = 0)¶ Bases:
objectRepresents Tweet
-
created_at: datetime.datetime = None¶
-
favorite_count: int = 0¶
-
id: int = None¶
-
in_reply_to_screen_name: str = None¶
-
is_truncated: bool = False¶
-
lang: str = None¶
-
name: str = None¶
-
retweet_count: int = 0¶
-
retweeted: bool = False¶
-
screen_name: str = None¶
-
text: str = None¶
-
tweet_id_str: str = None¶
-
-
class
RPA.Twitter.Twitter¶ Bases:
objectTwitter is a library for accessing Twitter using developer API. The library extends tweepy library.
Authorization credentials can be given as parameters for
authorizekeyword or keyword can read them in as environment variables:TWITTER_CONSUMER_KEY
TWITTER_CONSUMER_SECRET
TWITTER_ACCESS_TOKEN
TWITTER_ACCESS_TOKEN_SECRET
Library usage requires Twitter developer credentials. Those can be requested from Twitter developer site
Examples
*** Settings *** Library RPA.Twitter *** Tasks *** Get user tweets and like them [Setup] Authorize @{tweets}= Get User Tweets username=niinisto count=5 FOR ${tweet} IN @{tweets} Like ${tweet} END
from RPA.Twitter import Twitter library = Twitter() library.authorize() tweets = library.get_user_tweets(username="niinisto", count=5) for tw in tweets: library.like(tw) tweets = library.text_search_tweets(query="corona trump") for tw in tweets: print(tw.text) user = library.get_user_profile("niinisto") library.follow(user) library.tweet("first tweet") me = library.get_me() print(me)
-
ROBOT_LIBRARY_DOC_FORMAT= 'REST'¶
-
ROBOT_LIBRARY_SCOPE= 'GLOBAL'¶
Authorize to Twitter API
- Parameters
consumer_key – app consumer key
consumer_secret – app consumer secret
access_token – user access token
access_token_secret – user access token secret
-
follow(user: str = None) → bool¶ Follow Twitter user
- Parameters
user – screen name of the user
- Returns
True if user was followed, False if not
-
get_me() → dict¶ Get Twitter profile of authenticated user
- Returns
user profile as dictionary or None
-
get_user_profile(username: str = None) → dict¶ Get user’s Twitter profile
- Parameters
username – whose profile to get
- Returns
profile as dictionary
-
get_user_tweets(username: str = None, count: int = 100) → list¶ Get user tweets
- Parameters
username – whose tweets to get
count – maximum number of tweets, defaults to 100
- Returns
list of user tweets
-
like(tweet: RPA.Twitter.Tweet = None) → bool¶ Like a tweet
- Parameters
tweet – as a class Tweet
- Returns
True if Tweet was liked, False if not
-
text_search_tweets(query: str = None, count: int = 100, geocode: str = None, lang: str = None, locale: str = None, result_type: str = 'mixed', until: str = None, since_id: str = None, max_id: str = None) → list¶ Search tweets defined by search query
Results types:
mixed : include both popular and real time results in the response
recent : return only the most recent results in the response
popular : return only the most popular results in the response
- Parameters
query – search query string of 500 characters maximum, including operators
count – maximum number of tweets, defaults to 100
geocode – tweets by users located within a given radius of the given latitude/longitude
lang – language code of tweets
locale – language of the query you are sending
result_type – type of search results you would prefer to receive, default “mixed”
until – tweets created before the given date
since_id – Returns only statuses with an ID greater than
max_id – only statuses with an ID less than
- Returns
list of matching tweets
-
tweet(content: str = None) → None¶ Make a tweet with content
- Parameters
content – text for the status update
-
unfollow(user: str = None) → bool¶ Unfollow Twitter user
- Parameters
user – screen name of the user
- Returns
True if user was followed, False if not
-
unlike(tweet: RPA.Twitter.Tweet = None) → bool¶ Unlike a tweet
- Parameters
tweet – as a class Tweet
- Returns
True if Tweet was unliked, False if not