抱歉交叉发帖 this issue这里是SO
所以我按照“https://docs.shopify.com/api/authentication/oauth”;指南并成功进行到“发出经过身份验证的请求”部分,然后我就停留在那里。这是我的代码(Java):
String payload = "{\"script_tag\":{\"src\":\"http:\\/\\/localhost:8080\\/js\\/shopify.js\",\"event\":\"onload\"}}";
String url = "https://pixolut-shopify-test.myshopify.com/admin/script_tags.json";
HttpPost post = new HttpPost(url);
post.setHeader("X-Shopify-Access-Token", accessToken);
post.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
HttpResponse resp = HttpClientBuilder.create().build().execute(post);
StatusLine statusLine = resp.getStatusLine();
if (statusLine.getStatusCode() != 200) {
throw new RuntimeException("Error inject script tag: %s", statusLine.getReasonPhrase());
}
我正在使用 apache httpclient (v4.3.1) 将我的请求发布到 Shopify。我发现的问题是我总是得到 HTTP/1.1 422 Unprocessable Entity
,我不知道我错在哪里。
如果我使用 postman 使用完全相同的负载、url 和访问 token 进行测试,我会得到以下响应:
{
"errors": {
"script_tag": "Required parameter missing or invalid"
}
}
有人可以帮忙吗?
更新
我得到了 422
响应的内容:
{"errors":{"src":["is invalid"]}}
最佳答案
我有同样的问题,使用curl。缺少的成分是设置请求的内容类型:
curl -H "X-Shopify-Access-Token: {token}" -H "Content-Type: application/json" -d "{\"script_tag\":{\"event\":\"onload\",\"src\":\"{script_uri}\"}}" https://{shop}.myshopify.com/admin/script_tags.json
您应该能够对 Postman 执行相同的操作:https://www.getpostman.com/docs/requests#headers
关于json - Shopify 集成 : trouble on making authenticated requests,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28998526/