skip to Main Content

Regarding the tweepy docs for using Twitter API v2 i should be able to like a tweet with the following code.

import tweepy
from keys import keys

# bearer token for twitter developers
client = tweepy.Client(bearer_token=keys["bearer_token"])

# checks for latest tweets
def like_tweets():

    like = client.like(1466906017120153601)
    print(like)

like_tweets()

I both tried to pass the tweet id as a string and as an integer. I checked the tweet id manually for correctness and also tried different tweet ids.
But i get the following error everytime:

File "C:UsersmynamepathtopythonPythonPython37site-packagestweepyclient.py", line 387, in like
id = self.access_token.partition('-')[0]
AttributeError: 'NoneType' object has no attribute 'partition'

Do you have ideas or suggestions how to solve this problem?

2

Answers


  1. Chosen as BEST ANSWER

    I was not able to encode the exact error, but found out, that this method need's the whole access data, including the consumer_token, consumer_secret, access_token and access_token_secret.


  2. I just came across the same issue.
    The solution was to specify the other tokens when creating the client:

    from os import environ
    import tweepy
    
    def new_client():
        return tweepy.Client(
        consumer_key=environ['CONSUMER_KEY'],
        consumer_secret=environ['CONSUMER_SECRET'],
        bearer_token=environ['BEARER_TOKEN'],
        access_token=environ['ACCESS_TOKEN'],
        access_token_secret=environ['ACCESS_TOKEN_SECRET'],
    )
    
    client = new_client()
    

    And then calling

    client.like(tweet_id=tweet_id)
    

    (letting the default option user_auth=True)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search