sferik / x-ruby

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

Follower counts #20

Closed seanwmitchell closed 5 months ago

seanwmitchell commented 5 months ago

Thanks for a very useful gem.

I tried to upgrade from the twitter-ruby gem to this new x-ruby gem and can't get follower counts data.

The x_client.get("users/me") method returned just a couple data points not including the followers_count.

I am able to send posts/tweets so its not an authentication issue.

On the previous gem, I have this code working perfectly to collect follower_counts:

require 'twitter'
require 'net/http'

client = Twitter::REST::Client.new do |config|
    config.consumer_key        = my_api_key
    config.consumer_secret     = my_api_key_secret
    config.access_token        = my_access_token
    config.access_token_secret = my_access_token_secret
end

return client.user.followers_count

Any suggestions of how to do it on the new x-ruby gem?

sferik commented 5 months ago
require "x"

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",
}

x_client = X::Client.new(**x_credentials)
user = x_client.get("users/me?user.fields=public_metrics")
user["data"]["public_metrics"]["followers_count"]