Skip to content

Instantly share code, notes, and snippets.

@mironal
Created February 27, 2022 02:15
Show Gist options
  • Save mironal/6ad38705ad729c71afec9816abccbfd4 to your computer and use it in GitHub Desktop.
Save mironal/6ad38705ad729c71afec9816abccbfd4 to your computer and use it in GitHub Desktop.
Sample code for Search Stream API using TwitterAPIKit.
func testExample() throws {
let client = TwitterAPIKit(
.bearer(
"<your token>"
))
let exp = expectation(description: "")
/*
// Before starting a Stream search, you need to add a Rule for the search.
client.v2.stream.postSearchStreamRules(
.init(operation: .add([.init(value: "cat has:media", tag: "cats with media")]))
).responseObject { response in
print(response.prettyString)
exp.fulfill()
}
client.v2.stream.getSearchStreamRules(.init()).responseObject { response in
print(response.prettyString)
exp.fulfill()
}
*/
client.v2.stream.searchStream(.init()).streamResponse(queue: .global(qos: .default)) { response in
print(response.prettyString)
}
wait(for: [exp], timeout: 60)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment