简体   繁体   中英

Twitter labs get users not returning tweets

im trying to get users tweets using the labs /users/ endpoint. This is the code I have so far:

fields = “created_at,description,pinned_tweet_id”

params = {“usernames”: “TwitterDev”, “user(dot)fields”: fields, “tweet(dot)fields”: “text”}

user_context_auth = OAuth1(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, TOKEN_SECRET)

response = requests.get(url=url, params = params, auth=user_context_auth)

print(“Response status: %s” % response.status_code)

print(“Body: %s” % response(dot)text)

As you can see Im requesting the “text” parameter of the tweet. However, when I send my request I only am returned the Profile infomation: {“data”{“id”:“2244994945”,“name”:“TwitterDev”,“pinned_tweet_id”:“1237435016134656006”,“username”,“TwitterDev”}}

Any ideas whats causing the issue?

This is because you also need to request that the pinned_tweet_id field is expanded in the response.

The full URL to call would be

https://api.twitter.com/labs/2/users/by?usernames=TwitterDev&user.fields=pinned_tweet_id&expansions=pinned_tweet_id

(the tweet.fields=text is redundant, as you'll always get the Tweet ID and text as a minimum return in the expansion)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM