【问题标题】:Shopify Private app API URL works in browser but not in API call using c#Shopify Private 应用 API URL 在浏览器中有效,但在使用 c# 的 API 调用中无效
【发布时间】:2016-03-14 17:04:31
【问题描述】:

我正在使用适用于浏览器但不适用于 API 调用的 shopify Private 应用 API URL。我收到{"The remote server returned an error: (401) Unauthorized."}

using (var client = new WebClient())
            {
                var values = new NameValueCollection();
                var since = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd HH:mm");
                client.Headers.Add(values);
               var response = client.DownloadString(string.Format("https://xxxx:xxxxx@abc.myshopify.com/admin/orders.json"));

                orders = JsonConvert.DeserializeObject<ShopifyApiObjects.SalesOrders>(response);
            }

如果有人有想法,请提供帮助。提前致谢。

【问题讨论】:

  • 该 API 的身份验证方案是什么样的?您很可能需要传入密钥(如果它使用 OAuth)或实际凭据。
  • 在 shopify 中,我们在 URL 中有 API 密钥和密码,所以我认为不需要身份验证
  • 尝试通过标头数据而不是 url 传递 apikeyapi_password

标签: c# api shopify


【解决方案1】:

如果您的商店有任何类型的重定向,基于 URL 的身份验证将被删除,因此 API 密码需要在请求的标头中传递。尝试添加:

client.Headers.Add("X-Shopify-Access-Token", YOUR_API_SECRET);

因为我假设您正在使用 values 来构建您的查询字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-19
    • 2014-03-08
    • 2019-03-20
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多