michimani / gotwi

A library for using the Twitter API v2 in the Go language. (It is still under development).
MIT License
127 stars 26 forks source link

author_id returns blank #291

Closed Peter-Lankton closed 2 years ago

Peter-Lankton commented 2 years ago

Hi @michimani excellent library,

I did encounter, what I think is a bug.

Whenever following the filteredstreams example I noticed that the t.Data.AuthorID is always blank on the returned output.

This was very tricky to track down for me lol.

I think maybe the endpoint is not being generated correctly if it is being done so dynamically.

For example when I hardcoded the endpoint to be the following;

searchStreamEndpoint = "https://api.twitter.com/2/tweets/search/stream?tweet.fields=author_id,id,text"

I was able to retrieve the author_id

Not, sure how to remedy it in the code but will try to do so...

cgrinds commented 2 years ago

hi @toul-codes if you're using the filtered_stream example you'll need to change this line https://github.com/michimani/gotwi/blob/faead303122de77e9108116f7818312a5a41d4cd/_examples/4_filtered_stream/filtered_stream.go#L92

to something like this, which tells Twitter to return the author id in the response.

p := &types.SearchStreamInput{
    TweetFields: fields.TweetFieldList{
        fields.TweetFieldAuthorID,
    },
}
michimani commented 2 years ago

Hi @toul-codes, thanks for asking this question.

As @cgrinds already commented, could you try to fix the SearchStreamInput?

Twitter API v2 requires some fields to be explicitly specified in order to be included in the response, and this author_id is one of them.

Thanks for your prompt advice! > @cgrinds

Peter-Lankton commented 2 years ago

Hi thank you @cgrinds and @michimani for the quick response. The proposed code worked!