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

I can't get public_metrics with method get_users_tweets #1914

Closed
profAndreHolanda opened this issue Jun 13, 2022 · 3 comments
Closed

I can't get public_metrics with method get_users_tweets #1914

profAndreHolanda opened this issue Jun 13, 2022 · 3 comments
Labels
Invalid This is not valid No Reproduction This is not reproducible

Comments

@profAndreHolanda
Copy link

Hi,

I'm having trouble recently with tweepy anda API V2
I can't get public_metrics with method get_users_tweets

This is what I have inside the paginator,

r=client.get_users_tweets(id=user_id,
tweet_fields='public_metrics',
start_time = '2022-06-10T18:02:14Z',
max_results=100)

only the r.data, is filled with .id and .text
I don't know if the metrics were supposed to be on .includes since they were not meant to be expansions (i think) but is empty anyway.

I could not understand the few explanations out there, nor could I find anyone else who did.

I hope you can help with this.

thanks in advance
Andre Holanda

here is the output os response 'r'
r
Out[48]: Response(data=[, , , , , ], includes={}, errors=[], meta={'result_count': 6, 'newest_id': '1536354739134283776', 'oldest_id': '1535421211848630274'})

r.data
Out[49]:
[,
,
,
,
,
]

r[0]
Out[56]:
[,
,
,
,
,
]

r[1]
Out[57]: {}

r[2]
Out[58]: []

r[3]
Out[59]:
{'result_count': 6,
'newest_id': '1536354739134283776',
'oldest_id': '1535421211848630274'}

@Harmon758
Copy link
Member

Response.data should be a list of Tweet objects when returned from Client.get_users_tweets.
I'm not sure what's being returned here, but that shouldn't be possible, since it's not even valid Python syntax.
I'm unable to reproduce this. Do you have an example of this with a specific user_id?

For code block usage, see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

@Harmon758 Harmon758 added Need Follow-Up This needs to be followed up on to be actionable No Reproduction This is not reproducible labels Jun 13, 2022
@profAndreHolanda
Copy link
Author

Got it,
response = client.get_users_tweets(user_id,
tweet_fields=['text','created_at','public_metrics'],
start_time = '2022-06-10T18:02:14Z',
max_results=100)
for tweet in response.data:
print (tweet.public_metrics)

returns the dict public_metrics

{'retweet_count': 228, 'reply_count': 1354, 'like_count': 1562, 'quote_count': 76}
{'retweet_count': 189, 'reply_count': 0, 'like_count': 0, 'quote_count': 0}
{'retweet_count': 333, 'reply_count': 0, 'like_count': 0, 'quote_count': 0}
{'retweet_count': 595, 'reply_count': 0, 'like_count': 0, 'quote_count': 0}
{'retweet_count': 437, 'reply_count': 2808, 'like_count': 3702, 'quote_count': 406}
{'retweet_count': 984, 'reply_count': 1561, 'like_count': 6471, 'quote_count': 112}

@Harmon758
Copy link
Member

Yes, that's working as expected.

I'm still unable to reproduce the output in your initial comment.
With the reproducible example from your deleted comment:

Response(data=[<Tweet id=1536354739134283776 text='Amanhã, terça, às 11h, concederei uma entrevista coletiva em Curitiba para falar acerca do meu destino junto com o União Brasil no Paraná. https://t.co/GrhQZhhMAD'>, <Tweet id=1536135386707132420 text='RT @marciocoimbramg: Não tenho dúvidas que #Moro será responsável por construir uma resistência. Sob sua liderança, vejo a articulação de u…'>, <Tweet id=1536112459030966273 text='RT @JorgeBPontes: Não esqueçamos o que ocorreu na Petrobras. A corrupção sistêmica nos governos do PT foi avassaladora e a inocência de Lul…'>, <Tweet id=1535678882728271872 text="RT @Estadao: EDITORIAL: 'Lula quer imprensa encabrestada: Candidato petista defende que veículos de comunicação não sejam livres para publi…">, <Tweet id=1535644864737599490 text='Jeanine Áñez assumiu a Presidência em virtude da renúncia de Evo Morales. Foi presa e condenada com a volta do regime bolivariano, ainda que sob outro presidente. É uma presa política nessa nova América Latina. Também estou surpreso com o silêncio de muitos. https://t.co/ALyr7qNrNs'>, <Tweet id=1535421211848630274 text='“Ninguém pode esquecer que ocorreu no Brasil, no mensalão, na Lava Jato.”Palavras fortes do Min Fux. Todo o roubo ou o saque dos cofres públicos está sendo infelizmente esquecido. A crise é acima de tudo moral. https://t.co/5S2VYIjSu6'>], includes={}, errors=[], meta={'result_count': 6, 'newest_id': '1536354739134283776', 'oldest_id': '1535421211848630274'})

As you said, the Tweet objects are hidden when pasted outside a code block, due to the angle brackets.
Again, for code block usage, see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

As for public_metrics not being printed when printing the Response object, see the FAQ section in the documentation about this:

If you are simply printing the objects and looking at that output, the string representations of API v2 models/objects only include the default fields that are guaranteed to exist.

The objects themselves still include the relevant data, which you can access as attributes or by subscription.

@Harmon758 Harmon758 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2022
@Harmon758 Harmon758 added Invalid This is not valid and removed Need Follow-Up This needs to be followed up on to be actionable labels Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid This is not valid No Reproduction This is not reproducible
Projects
None yet
Development

No branches or pull requests

2 participants