简体   繁体   English

shopify嵌入式应用程序 - 需要获取订单列表

[英]shopify embedded app - need to get list of orders

I have initialized a Shopify Embedded App. 我已经初始化了Shopify嵌入式应用程序。 How do I get data (for example the data accessed at /admin/orders.json)? 如何获取数据(例如在/admin/orders.json中访问的数据)? Since I am already in the store's domain at this point can I call the URL directly, or do I need to make a call to my web server, which will in turn call the api? 由于此时我已经在商店的域中,我可以直接调用URL,还是需要调用我的Web服务器,然后调用api? If I am meant to call my own server how am I meant to handle security (ie how do I know that the request is legit)? 如果我打算打电话给我自己的服务器我怎么处理安全性(即我怎么知道请求是合法的)?

Thanks 谢谢

If you call the URL directly in your embedded app's JavaScript then the request will be send but you won't be able to read the response due to the lack of Access-Control-Allow-Origin header in Shopify's response. 如果您直接在嵌入式应用程序的JavaScript中调用URL,则会发送请求,但由于Shopify的响应中缺少Access-Control-Allow-Origin标头,您将无法读取响应。 For example in Chrome console you'll see an error like this: 例如,在Chrome控制台中,您会看到如下错误:

Shopify没有CORS错误

This is the result of same-origin policy, a security mechanism implemented in all major browsers. 这是同源策略的结果,这是一种在所有主流浏览器中实现的安全机制。

So you first need to call your server and then make a call to the Shopify API. 因此,您首先需要调用您的服务器,然后调用Shopify API。 You can ensure that the request from your app is legit by verifying the HMAC that Shopify appends as a query param. 您可以通过验证Shopify作为查询参数附加的HMAC来确保您的应用程序的请求是合法的。

You make calls using the API. 您使用API​​拨打电话。 If you don't know how to make calls to a REST-ful API, rest assured there are several thousand web sites out there that explain it in more than enough detail. 如果您不知道如何调用REST-ful API,请放心,有数千个网站可以解释它的详细信息。

If your App is based on Ruby or Python, there are tons of examples. 如果你的应用程序基于Ruby或Python,那么有很多例子。 Shopify even provides an excellent Rails App at their Github account showing exactly how to do it. Shopify甚至在他们的Github帐户中提供了一个优秀的Rails应用程序,显示了如何做到这一点。

Other languages are also well supported, from PHP to Elixir. 其他语言也得到很好的支持,从PHP到Elixir。 Spend a few minutes checking out samples and you'll go far. 花几分钟检查样品,你会走得很远。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM