gpt4 book ai didi

c# - Shopify 访问 token 返回 null

转载 作者:行者123 更新时间:2023-11-30 21:33:16 29 4
gpt4 key购买 nike

在旅程即将结束时,我意识到我的访问 token 即将变为空。我在带有 C# 的 visual studio 中使用 RectSharp 启动并运行 shopify 应用程序,一切正常按安装,然后我被带回 visual studio 并被告知 accessToken 为 null D:

这是错误的一些图片和我的调试 click here for image

这是我注意到在 r 周围弹出的错误,它是用 rectSharp 编写的,对我来说看起来是正确的。

{{
"error": "822: unexpected token at 'client_id=6e83a9e8b79dccbad77530c7273e3e00&client_secret=03cfa0ef9b451868bb0160e4ad75e0ec&code=3a941fe03d9fc0ea0d4226f9f4af316f'"
}}

这是我的授权码:

 public ActionResult install(string shop, string signature, string timestamp)
{
string r = string.Format("https://{0}/admin/oauth/authorize?client_id={1}&scope=read_fulfillments,write_fulfillments,read_orders,write_products&redirect_uri=https://{2}/fulfillment/auth", shop, apiKey, appUrl);
return Redirect(r);
}

public ActionResult auth(string shop, string code)
{

string u = string.Format("https://{0}/admin/oauth/access_token", shop);

var client = new RestClient(u);

var request = new RestRequest(Method.POST);

request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", "application/json");

request.AddParameter("application/x-www-form-urlencoded", "client_id=" + apiKey + "&client_secret=" + secretKey + "&code=" + code, ParameterType.RequestBody);

var response = client.Execute(request);

var r = JsonConvert.DeserializeObject<dynamic>(response.Content);
var accessToken = r.access_token;
accesstokenmain = r.access_token;
//save shop token and information to database
SaveShopToken(shop, (string)accessToken);

//Part 5
//create a un-install web hook
//you want to know when customers delete your app from their shop

string unInstallUrlCallback = "https://8a047f39.ngrok.io/fulfillment/uninstall";

string shopAdmin = string.Format("https://{0}/admin/", shop);

var webHook = new WebHookBucket();
webHook.Whook = new WebHook { Format = "json", Topic = "app/uninstalled", Address = unInstallUrlCallback };

CreateUninstallHook(shopAdmin, "webhooks.json", Method.POST, (string)accessToken, webHook);

return Redirect(AskCustomerCharge(shop, (string)accessToken));


// return View();
}

public void SaveShopToken(string shop, string token)
{
using (var con = new fulfillmentdbEntities())
{
if (con.ShopTokens.Any(c=>c.Shop == shop))
{

} else
{
con.ShopTokens.Add(new ShopToken { Shop = shop, Token = token, InstallDate = DateTime.Now });
}

con.SaveChanges();
}
}

最佳答案

请尝试改变 request.AddHeaderrequest.AddParameter 如下

request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", $"client_id={apiKey}&client_secret={secretKey}&code={code}, ParameterType.RequestBody);

关于c# - Shopify 访问 token 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51549805/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com