'Tweepy Client.like() throws AttributeError: 'NoneType' object has no attribute 'partition'
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:\Users\myname\pathtopython\Python\Python37\site-packages\tweepy\client.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?
Solution 1:[1]
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.
Solution 2:[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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Luca König |
| Solution 2 | The Happy Monkey |
