我正在尝试使用etsy并使用oauth进行验证。通过在第一个请求url中执行以下操作,我成功地获得了一个成功的令牌:
scopes = ["email_r", "feedback_r", "listings_r", "transactions_r"]
oauth_consumer = OAuth::Consumer.new(Rails.application.secrets.etsy_api_key,
Rails.application.secrets.etsy_api_secret,
site: "https://openapi.etsy.com/v2"
)
oauth_consumer.options[:request_token_path] = "/oauth/request_token?scope=#{scopes.join('%20')}"
request_token = oauth_consumer.get_request_token(oauth_callback: new_etsy_authentication_url)
redirect_to request_token.params[:login_url]然后,用户通过etsy验证页面,在回调url上,我有以下内容:
current_user.update(etsy_auth: {
oauth_token: params["oauth_token"],
oauth_verifier: params["oauth_verifier"],
oauth_created_at: Time.current.to_i
})我成功地保存了etsy oauth_token和oauth_verifier。
问题从那以后开始。我尝试过很多方法来向用户发出请求,但是我总是得到oauth_token=rejected。下面是我迄今为止所做的工作的一个例子:
oauth_consumer = OAuth::Consumer.new(Rails.application.secrets.etsy_api_key,Rails.application.secrets.etsy_api_secret,site: "https://openapi.etsy.com/v2")
access_token = OAuth::AccessToken.new(oauth_consumer, oauth_token: current_user.etsy_auth["oauth_token"], oauth_secret: current_user.etsy_auth["oauth_verifier"])
access_token.request(:get, "/users/__SELF__")在此之前,我是否应该执行另一个请求,以获得另一个临时oauth_token和oauth_secret?
我尝试过这样做:request_token = oauth_consumer.get_request_token和我得到了一个临时的oauth_token和oauth_token_secret以及oauth_consumer_key (我不知道该如何使用它)。我得到了临时标记,并尝试了许多组合,但没有成功,我总是得到oauth_token=rejected。我还没有弄清楚是否应该在哪里使用oauth_consumer_key,以及oauth_verifier是否实际上是oauth_secret。
我遗漏了什么?任何帮助都是非常感谢的。
发布于 2021-04-12 16:11:36
我终于找到了需要做的事。在对Etsy的最初请求之后,我必须存储oauth_token和oauth_secret。然后Etsy也返回oauth_verifier。
在此之后,为了获取和执行每个请求,您需要将所有三个请求都发送到工作中。
https://stackoverflow.com/questions/67044056
复制相似问题