为Shopify应用程序生成访问令牌时出错

时间:2015-12-25 05:25:37

标签: java oauth oauth-2.0 shopify

我已经为Shopify商店建立了一个应用程序,它工作正常,直到昨天。链接到随后的文档以创建Shopify应用:https://docs.shopify.com/api/authentication/oauth

但是现在生成访问令牌时似乎出现了错误。我一直在收到错误:

{"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

有没有人遇到同样的错误?请帮忙

1 个答案:

答案 0 :(得分:0)