Python – API.verify_credentials() in Tweepy
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.verify_credentials()
The verify_credentials()
method of the API
class in Tweepy module is used to verify whether the supplied user credentials are valid or invalid.
Syntax : API.verify_credentials(include_entities, skip_status, include_email)
Parameter :
- include_entities : entities node will not be included when set to false, defaults to true.
- skip_status : statuses will not be included in the returned user objects, defaults to false.
- include_email : email will be returned in the user objects as a string.
Returns : an object of class User
Example 1 :
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
if api.verify_credentials() = = False :
print ( "The user credentials are invalid." )
else :
print ( "The user credentials are valid." )
|
Output :
The user credentials are valid.
Example 2 : Fetching the verified user.
user = api.verify_credentials()
print ( "The user has " + str (user.followers_count) + " followers." )
print ( "The user has " + str (user.friends_count) + " friends." )
|
Output :
The user has 44 followers.
The user has 1016 friends.
Last Updated :
10 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...