daneden / Twift

🐦 An async Swift library for the Twitter v2 API 🚧 WIP
MIT License
111 stars 25 forks source link

Fix encoding of colon in request query parameters #53

Closed Tunous closed 2 years ago

Tunous commented 2 years ago

Given search API call that uses colon character (:) in its query Twitter is always returning unauthorized response with about:blank type.

Example call:

try await client.searchRecentTweets(query: "conversation_id:1575266034457579520")

Received response:

{
  "detail": "Unauthorized",
  "status": 401,
  "title": "Unauthorized",
  "type": "about:blank"
}

From my investigation it looks like the request fails because of : character in query, which Twitter expects to be encoded as %3A. That is confirmed by looking at documentation: https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query#adding-a-query

Manually adding colon encoding in addition to system behavior resolves the issue.

Tested on iOS 16.0 simulator.