You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A number of endpoints in Twitter API v2 take optional parameters that contain a dot/period. Example: On GET /2/tweets/:id (lookup by single ID) under the section Query Parameters, you can see optional parameters with names like media.fields and user.fields.
In peony-twitter, parameters are passed as keyword arguments, whose names cannot contain a period. The workaround I found (and maybe this is the intended way) is to make a dict of dotted parameters and pass them into the method call as **kwargs. I searched through the documentation and didn't find anything about this. Should this be documented?
Example code that uses user.fields, both the wrong way and right way:
importasyncio, peonytwclient_v2user=peony.PeonyClient(
consumer_key=TWITTER_CONSUMER_KEY,
consumer_secret=TWITTER_CONSUMER_SECRET,
access_token=TWITTER_ACCESS_TOKEN,
access_token_secret=TWITTER_ACCESS_TOKEN_SECRET,
api_version="2",
suffix="",
)
# Goal: get a tweet that includes the author's description/bio# This will not worktweet_v2_task=twclient_v2user.api.tweets["1292589384265601029"].get(
expansions="author_id",
user.fields="description"# "user.fields" is invalid python syntax, but Twitter expects that name
)
# However, this will workdotted_parameters= {"user.fields" : "description"}
tweet_v2_task=twclient_v2user.api.tweets["1292589384265601029"].get(
expansions="author_id",
**dotted_parameters
)
loop=asyncio.get_event_loop()
tweet_v2=loop.run_until_complete(tweet_v2_task)
loop.close()
print(tweet_v2)
The text was updated successfully, but these errors were encountered:
I haven't tested the API v2 with Peony yet and I wanted to test it before the next release.
I did see these parameters and I was wondering how I should set them.
So it should be documented when I've made up my mind on how it should be used.
I'm thinking about adding a parameter to the client that would set the default parameters for every request.
You would still be able to set it for each request of course.
Dotted parameters obviously won't work the same way as the other parameters. I still want to be able to use them directly as parameters (not by unwrapping a dict, though that would still work). Probably it will be a Parameter class, that would make it look like this:
tweet_v2_task=twclient_v2user.api.tweets["1292589384265601029"].get(
Parameter("user.fields", "description"), # it has to be before the keyword argumentsexpansions="author_id"
)```
A number of endpoints in Twitter API v2 take optional parameters that contain a dot/period. Example: On GET /2/tweets/:id (lookup by single ID) under the section Query Parameters, you can see optional parameters with names like
media.fields
anduser.fields
.In peony-twitter, parameters are passed as keyword arguments, whose names cannot contain a period. The workaround I found (and maybe this is the intended way) is to make a dict of dotted parameters and pass them into the method call as
**kwargs
. I searched through the documentation and didn't find anything about this. Should this be documented?Example code that uses
user.fields
, both the wrong way and right way:The text was updated successfully, but these errors were encountered: