sferik / x-ruby

A Ruby interface to the X API.
MIT License
68 stars 13 forks source link

Add Example of using the recent tweet search endpoint #25

Closed anandvc closed 2 months ago

anandvc commented 2 months ago

I'd like to request an example in the README of how to call this endpoint with a basic query: https://api.twitter.com/2/tweets/search/recent

sferik commented 2 months ago

The following example code should work, as long as you substitute credentials from an app/project that is authorized to access the search API. For more details, see the search API documentation.

x_credentials = {
  api_key: "INSERT YOUR X API KEY HERE",
  api_key_secret: "INSERT YOUR X API KEY SECRET HERE",
  access_token: "INSERT YOUR X ACCESS TOKEN HERE",
  access_token_secret: "INSERT YOUR X ACCESS TOKEN SECRET HERE"
}

client = X::Client.new(**x_credentials)
query = "foo"
client.get("tweets/search/recent?query=#{query}")

If this code produces an error, please reply with it here so I can help you debug the issue.

sferik commented 2 months ago

@anandvc Is this example sufficient for your purposes?

sferik commented 2 months ago

Closing this issue. Please reopen if this code doesn't work for you.