Skip to content

OAuth 1.0a Access Tokens not working for v1 client #33

@danwetherald

Description

@danwetherald
class XService
  def initialize(access_token:, access_token_secret:)
    x_credentials = {
      api_key: Rails.application.credentials.dig(:x, :api_key),
      api_key_secret: Rails.application.credentials.dig(:x, :secret_key),
      access_token:,
      access_token_secret:
    }

    @client = X::Client.new(**x_credentials)
    @v1_client = X::Client.new(base_url: "https://api.twitter.com/1.1/", **x_credentials)
  end

  def verify_credentials
    @v1_client.get("account/verify_credentials.json")
  end
end

the api_key and the api_key_secret come from our developer dashboard, we are supplying the acquired access tokens but we get errors:

Bad Authentication data.

Keep in mind, we know these credentials are valid, I have a feeling this has to do with combining oauth acquired access tokens and our apps api keys/secrets?

Working example

BASE_URI = "https://api.twitter.com"

consumer = OAuth::Consumer.new(Rails.application.credentials.dig(:x, :api_key), Rails.application.credentials.dig(:x, :api_secret), site: BASE_URI)

@oauth_client = OAuth::AccessToken.new(consumer, access_token, access_token_secret)

@oauth_client.get("/1.1/account/verify_credentials.json")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions