我已经为 Shopify 商店构建了一个应用程序,直到昨天它都运行良好。链接到创建 Shopify 应用程序所遵循的文档:https://docs.shopify.com/api/authentication/oauth
但是现在生成访问 token 时似乎出现错误。我在响应中收到错误:
{"error":"795: unexpected token at 'code=<my-code>\u0026client_secret=<my-secret>\u0026client_id=<my-client-id>'"}
以下是用 Google App Script 编写的代码要点。
function doPost(e)
{
try
{
var client_id = e.parameter['client_id'];
var client_secret = e.parameter['client_secret'];
var code = e.parameter['code'];
var shopUrl = e.parameter['shopUrl'];
var headers = {
"Accept":"application/json",
"Content-Type":"application/json"
};
var payload = {
"client_id" : client_id,
"client_secret" : client_secret,
"code": code
};
var options =
{
"method" : "POST",
"payload" : payload,
"headers" : headers,
"muteHttpExceptions":true
};
var response = UrlFetchApp.fetch(shopUrl, options);
var data = response.getContentText().split('"')[3];
//response variable gives the following response
// {"error":"795: unexpected token at 'code=<my-code>\u0026client_secret=<my-client-secret>\u0026client_id=<my-client-id>'"}
return ContentService.createTextOutput(data).setMimeType(ContentService.MimeType.TEXT);
}//try
catch(e)
{
//log the exception
}//catch
}//doPost
有人遇到过同样的错误吗?请帮忙
最佳答案
- 确保您请求的网址正确,它就像 “https://[YOUR_SHOP_DOMAIN]/admin/oauth/access_token”。
- 确保您提供了正确的 ID 和密码。
- 在此处检查我的 PHP 代码以获取 Shopify 访问 token : ShopifyClient.php (滚动到函数“getAccessToken”)
关于java - 为 Shopify 应用程序生成访问 token 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34460240/