无法接收我的 Shopify 应用的永久访问令牌 [英] Unable to receive a permanent access token for my Shopify App
问题描述
我正在按照 Shopify 说明获取特定应用/商店组合的永久令牌 (.它正在为我们获取永久访问令牌.
变量 sess
现在将包含两件事:
- 商店的 *.myshopify.com 域 (
url
) - 保存以备将来使用的永久访问令牌(
令牌
)
正如约翰达夫所说 - 我们已经有了一个访问令牌!我们不需要发布到https://SHOP_NAME.myshopify.com/admin/oauth/access_token
.它在 shopify_app
gem 生成的代码中为我们处理.
在我的 finalize 方法中,我添加了一行:
def 完成if response = request.env['omniauth.auth']sess = ShopifyAPI::Session.new(params['shop'], response['credentials']['token'])Shop.find_or_create_by_myshopify_domain(sess.url, access_token: sess.token)...
这将创建一个商店并为其分配访问令牌.我的 Shop 模型具有属性 myshopify_domain
和 access_token
.
将来,如果我想为该商店使用 ShopifyAPI,我只需按照 shopify_api gem 主页上的说明进行操作即可一个>
我花了几个小时试图解决这个问题.我不确定文档如何更清晰.希望如果问题再次出现,人们会找到这个 StackOverflow 页面!
希望对您有所帮助.
干杯,尼克
I'm following the Shopify instructions to get a permanent token for a particular app/shop combination (http://api.shopify.com/authentication.html).
I'm able to get the temporary token and then use a simple html form to receive a permanent token:
But the response I get is: {"error":"invalid_request"}
Can you help me, please? I searched everywhere (Stackoverflow, Shopify support forums, etc...) but cannot find a clue on how to solve this. My app is online and hosted on Heroku.
Thanks,
I think we have similar minds! I was experiencing the exact same issue as you. I think we were both confused by the documentation!
I generated my app using the shopify_app
gem. This created the following method in login_controller.rb
:
def finalize
if response = request.env['omniauth.auth']
sess = ShopifyAPI::Session.new(params['shop'], response['credentials']['token'])
session[:shopify] = sess
flash[:notice] = "Logged in"
redirect_to return_address
session[:return_to] = nil
else
flash[:error] = "Could not log in to Shopify store."
redirect_to :action => 'index'
end
end
Line 3 of that (ShopifyAPI::Session.new
) is doing Step 2 of the Shopify Authentication for us. It's fetching us a permanent access token.
The variable sess
will now contain two things:
- The *.myshopify.com domain of the shop (
url
) - A permanent access token to save for future use (
token
)
As John Duff said - we already have an access token! We don't need to POST to https://SHOP_NAME.myshopify.com/admin/oauth/access_token
. It's handled for us in the code generated by the shopify_app
gem.
In my finalize method, I added a line:
def finalize
if response = request.env['omniauth.auth']
sess = ShopifyAPI::Session.new(params['shop'], response['credentials']['token'])
Shop.find_or_create_by_myshopify_domain(sess.url, access_token: sess.token)
...
This creates a shop and assigns it the access token. My Shop model has the attributes myshopify_domain
and access_token
.
In the future, if I want to use the ShopifyAPI for that shop, I can just follow the instructions found on the shopify_api gem homepage
I spent hours trying to nut this one out. I'm not sure how the documentation could be clearer. Hopefully if the issue comes up again, people find this StackOverflow page!
I hope this was a help for you.
Cheers, Nick
这篇关于无法接收我的 Shopify 应用的永久访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!