reluce / szurubooru-toolkit

Python package and script collection to manage your szurubooru image board.
GNU General Public License v3.0
41 stars 11 forks source link

Can't get import-from-twitter to work #34

Closed Kalidibus closed 1 year ago

Kalidibus commented 1 year ago

Hi, I've been trying for a while now to get import-from-twitter working.

I enabled the developer account on twitter, generated the consumer key and secret, and generated the account token and secret, and put them into the config.toml

Whenever I run the command for the same user-ID, I keep getting either "you don't have permission" or a error 403. I've tried regenerating everything several times and still can't get it working. Any help would be greatly appreciated.

Kalidibus commented 1 year ago

This seems to be the error:

[ERROR] [02.04.2023, 05:14:29 UTC] [import-from-twitter.<module>]: An error has been caught in function '<module>', process 'MainProcess' (15), thread 'MainThread' (140594436605760): Traceback (most recent call last): File "/usr/local/bin/import-from-twitter", line 6, in <module> sys.exit(main()) File "/szurubooru-toolkit/src/szurubooru_toolkit/scripts/import_from_twitter.py", line 80, in main tweets = twitter.get_media_from_liked_tweets(user_id, limit) File "/szurubooru-toolkit/src/szurubooru_toolkit/twitter.py", line 62, in get_media_from_liked_tweets response = self.client.get_liked_tweets( File "/usr/local/lib/python3.10/site-packages/tweepy/client.py", line 629, in get_liked_tweets return self._make_request( File "/usr/local/lib/python3.10/site-packages/tweepy/client.py", line 126, in _make_request response = self.request(method, route, params=request_params, File "/usr/local/lib/python3.10/site-packages/tweepy/client.py", line 99, in request raise Forbidden(response) tweepy.errors.Forbidden: 403 Forbidden When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.

As far as I can tell, I have an app attached to a project by default.

reluce commented 1 year ago

Hey, are you sure the used_id is correct? It should be a long integer number.

Kalidibus commented 1 year ago

I'm pretty sure, it's 9 numbers, and it matches the 9 numbers at the start of the "access_token" before the dash. I also pulled it from the link in the guide.

reluce commented 1 year ago

Can you make sure it's an elevated app and not a standalone app? Mine looks as follows:

image

The access token needs read permissions.

Kalidibus commented 1 year ago

Can you make sure it's an elevated app and not a standalone app? Mine looks as follows:

The access token needs read permissions.

So mine is a "Free" access level project. I don't see anywhere how to make it "Elevated". I do see an upgrade to "Basic" but that is $100 USD a month?

Kalidibus commented 1 year ago

twit

Kind of looks like there isn't an option for a free account that let's you pull tweets anymore.

reluce commented 1 year ago

Yeah I don't get how the new Twitter API works either as I'm still able to use my existing app without paying anything. I'll leave this issue open just in case someone has a solution for this.

reluce commented 1 year ago

So my project had exactly the same problem as yours. Luckily, gallery-dl supports Twitter as well, so you can just use the import-from-url script, e.g.:

import-from-url --cookies ~/cookies.txt --range ':100' "https://twitter.com/<USERNAME>/likes

Version 0.9.0 is needed though as the --cookie flag was introduced there.

Kalidibus commented 1 year ago

So my project had exactly the same problem as yours. Luckily, gallery-dl supports Twitter as well, so you can just use the import-from-url script, e.g.:

import-from-url --cookies ~/cookies.txt --range ':100' "https://twitter.com/<USERNAME>/likes

Version 0.9.0 is needed though as the --cookie flag was introduced there.

First of all, I'm really excited for the new features in 0.9, the auto-tag by md5 is something I've been hoping since starting with szurubooru, so thanks!

I tried running this, but for some reason "import-from-url" is showing as not a valid command. I'm using the docker image (just upgraded it to 0.9 and verified that import-from-booru is working). Is there a step to link gallery-dl I'm missing?

image

reluce commented 1 year ago

How did you update the container/image? In your bash shell, you can use pip list --local | grep szuru to view which version is installed.

I had to discard my previous container with docker container rm <id/name> and then (after pulling the newest image) start it again with docker-compose up -d .

Kalidibus commented 1 year ago

Ahh I just forgot to docker-compose pull like a dummy. It's working great now, thank you! The feature to add the user name as an artist tag is fantastic, thanks so much!