Saturday, November 16, 2024
Google search engine
HomeLanguagesPython – API.verify_credentials() in Tweepy

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 the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
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.




# fetching the verified user
user = api.verify_credentials()
  
# printing the information
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

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments