无法收到我的Shopify应用程序的永久访问令牌 [英] Unable to receive a permanent access token for my Shopify App

查看:264
本文介绍了无法收到我的Shopify应用程序的永久访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照Shopify的说明来获取特定应用程序/商店组合的永久令牌( http ://api.shopify.com/authentication.html ).

I'm following the Shopify instructions to get a permanent token for a particular app/shop combination (http://api.shopify.com/authentication.html).

我能够获取临时令牌,然后使用简单的html表单接收永久令牌:

I'm able to get the temporary token and then use a simple html form to receive a permanent token:

但是我得到的响应是:{错误":"invalid_request"}

But the response I get is: {"error":"invalid_request"}

可以帮我吗? 我到处搜索(Stackoverflow,Shopify支持论坛等),但是找不到有关如何解决此问题的线索. 我的应用程序在线且托管在Heroku上.

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.

谢谢

推荐答案

我认为我们有类似的想法!我遇到了与您完全相同的问题.我想我们俩都对文档感到困惑!

I think we have similar minds! I was experiencing the exact same issue as you. I think we were both confused by the documentation!

我使用shopify_app gem生成了我的应用.这在login_controller.rb中创建了以下方法:

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

其中的第3行(ShopifyAPI::Session.new)正在为我们执行 Shopify身份验证的步骤2 .它正在为我们获取一个永久访问令牌.

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.

变量sess现在将包含两个内容:

The variable sess will now contain two things:

  1. 商店的* .myshopify.com域(url)
  2. 永久访问令牌,以保存以备将来使用(token)
  1. The *.myshopify.com domain of the shop (url)
  2. A permanent access token to save for future use (token)

正如John Duff所说-我们已经有一个访问令牌! 我们不需要POST https://SHOP_NAME.myshopify.com/admin/oauth/access_token.这是由shopify_app gem生成的代码为我们处理的.

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.

在我的finalize方法中,添加了一行:

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)
  ...

这将创建一个商店并为其分配访问令牌.我的商店模型具有属性myshopify_domainaccess_token.

This creates a shop and assigns it the access token. My Shop model has the attributes myshopify_domain and access_token.

将来,如果我想为该商店使用ShopifyAPI,我可以按照 shopify_api gem主页上的说明进行操作. a>

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

我花了几个小时试图解决这一问题.我不确定文档如何清晰.希望如果问题再次出现,人们会发现此StackOverflow页面!

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.

干杯, 尼克

这篇关于无法收到我的Shopify应用程序的永久访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆