【问题标题】:Shopify API connection via Spring framework通过 Spring 框架连接 Shopify API
【发布时间】:2017-05-22 05:22:30
【问题描述】:

是否有人通过 Spring 执行了成功的 Shopify 身份验证(并使用了他们的 API)?

我一直在尝试使用 RestTemplate ,但无法登录:

RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject("https://apikey:password@shopname.myshopify.com/admin/shop.json",String.class);
    logger.info(result);

不幸的是,我不断收到这个:

org.springframework.web.client.HttpClientErrorException: 401 Unauthorized

虽然它在浏览器上运行良好!

  • 需要本地导入shopify证书吗?如果是,则已通过 keytool 完成。
  • 是否可以像我一样通过 RestTemplate 进行身份验证,还是需要使用 Auth0?

如果你们中的任何人成功了,请随时发布一个有效的 sn-p :)

非常感谢!

【问题讨论】:

    标签: spring rest spring-boot spring-security shopify


    【解决方案1】:
        RestTemplate restTemplate = new RestTemplate();
    
        HttpHeaders headers = new HttpHeaders();
        headers.set("X-Shopify-Access-Token", "xxxxx");
        //headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
        HttpEntity<String> entity = new HttpEntity<String>(headers);
    
        String result =  restTemplate.exchange("https://apikey:password@shopname.myshopify.com/admin/shop.json", HttpMethod.GET, entity, String.class).getBody();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 2010-11-17
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      相关资源
      最近更新 更多