This repository was archived by the owner on Apr 23, 2025. It is now read-only.
Repository navigation
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Twitter API v2 is rolling out
Twitter API v2 Early Access is available and there's preliminary support for it in the api-v2 branch. This code isn't ready for a CPAN release or use in production, yet, though I may do a TRIAL release, soon.
You're welcome to use the api-v2 branch to gain early access to the beta, discuss the design concepts, and review the code.
I'll likely not do a full release until:
Twitter API v2 issues
errorsin the response body/2/openapi.jsonreturnstext/htmlinstead ofapplication/json.Design decisions
I'm trying to wrap Twitter API v2 responses in objects that have accessors for expected fields. Successful responses return a JSON object with a
dataelement and may contain one or more ofincludes,meta, anderrorselements. Thedataelement may be a JSON object for a single response (a User or Tweet), or an array of JSON objects (Users or Tweets). I'm currently instantiating response by passing the decoded JSON directly tonewfor the various response types. E.g.,This works well enough. The response objects are effectively defined with:
But it might be better instantiate the response types with
->new(response => $decoded_json_response). That way, you'll always have access to the raw, unblessed, decoded response body Twitter sent. I don't like the deeper nesting, though, if it isn't necessary.Responses that return an array of results can be treated as arrays. E.g.,
The API spec specifies operation ID's for each path/http-method pair in camel case. I hate camel case. So, I've transformed Twitter's operation IDs to snake case. So,
findUserByIdbecomesfind_user_by_id.I intended to strictly use these transformed operation IDs as method names, letting the spec determine them. In fact, I'd hoped to be able to support v2 generating classes and methods directly from the spec. Until the spec is stable and validates, that's not practical. And there are some methods I've provided instead of using the semantics Twitter provides in the spec. E.g.:
These methods, defined in
Twitter::API::Trait::APIv2, take just a single argument, the target user ID or tweet ID. They extract the authenticated user ID from the OAuth access token. So, you can simply call:instead of:
Low-level calls
You don't have to use the convenience methods supplied by Twitter::API::Trait::APIv2. You can call the endpoints directly by using Twitter::API's get, post, put, and delete handlers directly. You'll get the decode JSON responses rather than Response objects. You can all use these lower-level call semantics to access endpoints Twitter adds before there are corresponding endpoints added to Twitter::API. E.g., rather than calling
find_user_by_username, you can call:Just provide the path (less the leading
/2/, with path agreements expanded and whatever parameters you require in%options. If the endpoint expects a JSON body argument, pass it with the-to_jsonoption.Join the discussion
If you're using Twitter::API and need API v2 support, let me know what you think of the work-in-progress. Let me know if I'm making any design mistakes so I can make corrections and adjustments before a CPAN release.
All reactions