【问题标题】:Semantics3 API, how to make a get request?Semantics3 API,如何发出获取请求?
【发布时间】:2014-06-29 19:53:08
【问题描述】:

我注册了 semantics3 API,以便可以使用他们的 UPC/EAN 产品搜索功能,并且我收到了我的 APIkey 和 APIsecret。现在,我想发出一个 propper Get 请求来测试它,然后最终将它合并到我自己的应用程序中。 我从他们的 GitHub 页面下载了 semantics3 java 项目。

无论如何,我如何使用自己的 UPC 或 EAN 代码进行 UPC/EAN 查询,以便获得我正在搜索的产品的 JSON 响应?

Semantics3Request 的构造函数如下所示:

public Semantics3Request(String apiKey, String apiSecret, String endpoint) {
    if (apiKey == null) { 
        throw new Semantics3Exception(
                "API Credentials Missing",
                "You did not supply an apiKey. Please sign up at https://semantics3.com/ to obtain your api_key."
            );
    }
    if (apiSecret == null) { 
        throw new Semantics3Exception(
                "API Credentials Missing",
                "You did not supply an apiSecret. Please sign up at https://semantics3.com/ to obtain your api_key."
            );
    }

    this.apiKey    = apiKey;
    this.apiSecret = apiSecret;
    this.endpoint  = endpoint;
    this.consumer = new DefaultOAuthConsumer(apiKey, apiSecret);
    consumer.setTokenWithSecret("", "");
}

一个重要的事情是我不明白我应该在String endpoint 中放什么,以便以后可以调用 Sematics3Request 类中的方法:addrunQueryfetchget返回 JSON 响应的方法。

【问题讨论】:

    标签: java json get-request


    【解决方案1】:

    您可以尝试使用此代码进行 UPC 搜索

        //To include, Github: https://github.com/Semantics3/semantics3-java
    import com.semantics3.api.Products;
    
    Products products = new Products(
        "SEM3xxxxxxxxxxxxxxxxxxxxxx",
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    );
    
    products
        .productsField( "upc", "934586730023" )
    JSONObject results = products.getProducts();
    System.out.println(results);
    

    您也可以访问http://semantics3.com 获取更多帮助

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2021-03-08
      • 2019-08-10
      • 2019-04-29
      • 2021-11-04
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      相关资源
      最近更新 更多