我有一个 Spree 3.7 应用程序,并且正在尝试使用店面API v2 来获取令牌。有人建议我使用他们的SDK,但我不明白如何使用 SDK
下面的例子:
标识来宾用户的购物车和订单。
const response = await client.cart.create()
const orderToken: string = response.data.attributes.token
没有明确说明它的response.data.attributes.token
来源或获取方式。
有没有人有一个如何使用 SDK 获取 API 令牌的示例?目前无法这样做。据说使用 /cart 我可以获得一个访客令牌按钮,试图获得以 404 结尾的响应
const orderToken: string = response.data.attributes.token
返回未知数据。我从哪里获取数据值?
import { makeClient } from '@spree/storefront-api-v2-sdk/dist/client';
async function asyncCall() {
console.log('calling');
// When using the SDK in a <script> tag or as part of a Webpack bundle
// targeted for the browser, instead use:
// import { makeClient } from '@spree/storefront-api-v2-sdk/dist/client'
const client = makeClient({
host: 'https://stern-telecom-react-salman15.c9users.io/'
});
console.log(client)
const createCart = await client.cart.create()
const orderToken = response.data.attributes.token
const addToCart = await client.cart.addItem({ orderToken }, {
variant_id: '1',
quantity: 1
})
console.log('orderToken',orderToken,'createCart',createCart);
// expected output: 'resolved'
}
asyncCall();