Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get authenticated user info? #168

Open
guntutur opened this issue Apr 16, 2024 · 3 comments
Open

How to get authenticated user info? #168

guntutur opened this issue Apr 16, 2024 · 3 comments

Comments

@guntutur
Copy link

i am using pool login for multiple account to get user_tweets

await api.pool.add_account("user1", "pass", "mail1@gmail.com", "")
await api.pool.add_account("user2", "pass", "mail2@ymail.com", "")
await api.pool.login_all()

async for tweet in api.user_tweets(target_id):

i just want to know from which logged in user (user1 or user2) the particular user tweet is acquired

@andylolz
Copy link
Contributor

andylolz commented Apr 16, 2024

@guntutur You can if you use api.user_tweets_raw. So:

from twscrape import API
from twscrape.models import parse_tweets

api = API()

await api.pool.add_account("user1", "pass", "mail1@gmail.com", "")
await api.pool.add_account("user2", "pass", "mail2@ymail.com", "")
await api.pool.login_all()

async for rep in api.user_tweets_raw(target_id):
    print(rep.__username)  # either user1 or user2
    for tweet in parse_tweets(rep.json()):
        ...

@guntutur
Copy link
Author

@guntutur You can if you use api.user_tweets_raw. So:

from twscrape import API
from twscrape.models import parse_tweets

api = API()

await api.pool.add_account("user1", "pass", "mail1@gmail.com", "")
await api.pool.add_account("user2", "pass", "mail2@ymail.com", "")
await api.pool.login_all()

async for rep in api.user_tweets_raw(target_id):
    print(rep.__username)  # either user1 or user2
    for tweet in parse_tweets(rep.json()):
        ...

Thanks andy, will try, is there any particular reason why __username ref only available in user_teeets_raw method?

@andylolz
Copy link
Contributor

@guntutur Good question. I don’t know the answer I’m afraid.

It’s possible it’s just set for debugging purposes, and later discarded.

It’s set just here:

setattr(rep, "__username", ctx.acc.username)

then it’s discarded when rep.json() is called:

for x in parse_tweets(rep.json(), limit):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants