【问题标题】:How to return a single asset OhMyBrew Laravel Shopify如何返回单个资产 OhMyBrew Laravel Shopify
【发布时间】:2019-12-16 13:41:25
【问题描述】:

我正在尝试使用 ohmybrew/laravel-shopify 在 Laravel 中以单个 Shopify 资产的形式获取对象:

$asset = $shop->api()->rest('GET', '/admin/api/'.ShopifyApp::api()->getVersion().'/themes/80166092888/assets.json?asset[key]=snippets/collection-grid-item.liquid');

我相信 $asset 的结果应该是 Shopify 资产但是当我 print_r($asset) 我得到这个:

stdClass 对象 ( [errors] => [response] => GuzzleHttp\Psr7\Response 对象 ( [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK [statusCode:GuzzleHttp\Psr7\Response:private] => 200 [headers:GuzzleHttp\Psr7\Response:private] => Array ([Date] => Array ([0] => Mon, 16 Dec 2019 13:28:09 GMT) [Content-Type] => Array ([ 0] => text/html; charset=utf-8 ) [Transfer-Encoding] => Array ( [0] => chunked ) [Connection] => Array ( [0] => keep-alive ) [Set-Cookie ] => 数组([0] => __cfduid=db02a99a7bcc26406fd2df1c93df79a7e1576502889;过期=格林威治标准时间 20 年 1 月 15 日星期三 13:28:09;路径=/;域=.myshopify.com;HttpOnly [1] => _secure_admin_session_id=7e129dcf87bda913d7916dcf8a50913 ; path=/admin; expires=Mon, 16 Mar 2020 13:28:09 -0000;secure; HttpOnly [2] => _secure_admin_session_id_csrf=7e198a5093ed7d91cfd87bda81a73126; path=/admin; expires=Mon, 16 Mar 2020 13:28:09 -0000; 安全; HttpOnly; SameSite=Lax [3] => _orig_referrer=; Expires=Mon, 30-Dec-19 13:28:09 GMT; Path=/; HttpOnly [4] => _landing_页面=%2Fadmin%2Fauth%2Flogin;过期=格林威治标准时间 19 年 12 月 30 日星期一 13:28:09;路径=/;仅Http [5] => _master_udr = eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWszTTJGbVl6VmlaaTA0TlRoa0xUUmtOemN0T0RZNU55MWxZV0l6WVRnM05HVmtObVlHT2daRlJnPT0iLCJleHAiOiIyMDIxLTEyLTE2VDEzOjI4OjA5LjU3OVoiLCJwdXIiOiJjb29raWUuX21hc3Rlcl91ZHIifX0%3D - e71a00abb5d0a41d5af672a647e68b4306ceea78;域=.myshopify.com;路径=/管理员;到期=2021 年 12 月 16 日星期四 13:28:09 -0000;安全的; HttpOnly ) [X-Sorting-Hat-PodId] => 数组 ( [0] => 87 ) [X-Sorting-Hat-ShopId] => 数组 ( [0] => 8865972324 ) [Vary] => 数组 ( [ 0] => Accept-Encoding ) [Referrer-Policy] => Array ( [0] => origin-when-cross-origin ) [X-Frame-Options] => Array ( [0] => DENY ) [X -ShopId] => Array ([0] => 8865972324) [X-ShardId] => Array ([0] => 87) [Cache-Control] => Array ([0] => no-cache, no- store ) [X-Shopify-Login-Required] => Array ([0] => true ) [Shopify-Auth-Mechanisms] => Array ([0] => password ) [Strict-Transport-Security] => Array ( [0] => max-age=7889238 ) [X-Shopify-Stage] => 数组 ( [0] => 生产 ) [Content-Security-Policy] => 数组 ( [0] => default-src ' self' 数据:blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://; block-all-mixed-content; child-src 'self' https:// shopify-pos://; connect-src 'self' wss:// https://*; frame-ancestors 'none'; img-src 'self' 数据:blob: https:;脚本-srchttps://cdn.shopify.comhttps://cdn.shopify.cnhttps://js-agent.newrelic.comhttps://bam.nr-data.nethttps://v.shopify.com'unsaf电子内联''不安全评估';升级不安全请求; report-uri /csp-report?source%5Baction%5D=login&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fauth&source%5Bsection%5D=admin&source%5Buuid%5D=8f3c44cc-7e32-48f5-a018-80df31681bc9) [X-Content-Type-Options] => Array ([0] => nosniff) [X-Download-Options] => Array ([0] => noopen) [X-Permitted-Cross-Domain-Policies] = > 数组([0] => 无)[X-XSS-Protection] => 数组([0] => 1;模式=块;报告=/xss-report?source%5Baction%5D=login&source%5Bapp%5D =Shopify&source%5Bcontroller%5D=admin%2Fauth&source%5Bsection%5D=admin&source%5Buuid%5D=8f3c44cc-7e32-48f5-a018-80df31681bc9 ) [X-Dc] => 数组 ([0] => gcp-us-east1 ,gcp-us-central1,gcp-us-central1 ) [NEL] => 数组 ( [0] => {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction ":0.0001} [1] => {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001} ) [Report-To] => Array ([0 ] => {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify" }]} [1] => {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]} ) [X-Request-ID ] => 数组 ( [0] => 8f3c44cc-7e32-48f5-a018-80df31681bc9 ) [CF-Cache-Status] => 数组 ( [0] => DYNAMIC ) [Expect-CT] => 数组 ( [0] => max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" ) [服务器] => 数组 ( [0] => cloudflare ) [CF-RAY] => 数组 ( [0] => 5460ffb34d00dc0b-LHR ) ) [headerNames:GuzzleHttp\Psr7\Response:private] => 数组 ( [date] => Date [content-type] => Content-Type [transfer-encoding] => Transfer-Encoding [connection] => Connection [set-cookie] => Set-Cookie [x-sorting-hat-podid] => X-Sorting-Hat-PodId [x-sorting-hat -shopid] => X-Sorting-Hat-ShopId [vary] => Vary [referrer-policy] => Referrer-Policy [x-frame-options] => X-Frame-Options [x-shopid] => X -ShopId [x-shardid] => X-ShardId [cache-control] => Cache-Control [x-shopify-login-required] => X-Shopify-Login-Required [shopify-auth-mechanisms] => Shopify -Auth-Mechanisms [严格-transport-security] => Strict-Transport-Security [x-shopify-stage] => X-Shopify-Stage [content-security-policy] => Content-Security-Policy [x-content-type-options] = > X-Content-Type-Options [x-download-options] => X-Download-Options [x-permitted-cross-domain-policies] => X-Permitted-Cross-Domain-Policies [x-xss-protection ] => X-XSS-Protection [x-dc] => X-Dc [nel] => NEL [report-to] => Report-To [x-request-id] => X-Request-ID [cf -cache-status] => CF-Cache-Status [expect-ct] => Expect-CT [server] => Server [cf-ray] => CF-RAY) [protocol:GuzzleHttp\Psr7\Response:private] => 1.1 [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream 对象([stream:GuzzleHttp\Psr7\Stream:private] => 资源 id #15 [size:GuzzleHttp\Psr7\Stream:private ] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [可读:GuzzleHttp\Psr7\Stream:private] => 1 [可写:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\ Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => 数组 ( ) ) ) [正文] => [链接] => [时间戳] => 数组 ( [0] => [1] => 1576502889.2041 ) )

我可以使用以下方法正确检索所有资产的列表:

$assets = $shop->api()->rest('GET', '/admin/api/'.ShopifyApp::api()->getVersion().'/themes/80166092888/assets.json');

但是这个对象不包含我需要的信息——尤其是每项资产的价值。

Shopify 文档详细说明了这是检索单个资产的正确方法:

GET /admin/api/2019-10/themes/#{theme_id}/assets.json?asset[key]=templates/index.liquid&theme_id=828155753

并且我可以成功地从浏览器发出 GET 请求以检索我想要的信息。

不确定我在 PHP/Laravel/OhMyBrew 方面做错了什么。

【问题讨论】:

    标签: php laravel shopify shopify-api


    【解决方案1】:

    我在 ohmybrew/Basic-Shopify-API 的文档中找到了答案,它是 laravel-shopify 包中实现的 API 包装器。 url 参数需要作为单独的参数传递给 rest 方法,如下所示:

    $assets = $shop->api()->rest('GET', '/admin/api/'.ShopifyApp::api()->getVersion().'/themes/80166092888/assets.json', ['asset[key]' => 'snippets/collection-grid-item.liquid']);
    

    希望对遇到同样问题的其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多