我注册了semantics3 API,以便我可以使用他们的UPC / EAN产品搜索功能,我收到了我的APIkey和APIsecret。现在,我想让一个propper获取测试它的请求,然后最终将它合并到我自己的应用程序中。 我从他们的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类中的方法:add
,runQuery
,{ {1}}和fetch
方法返回JSON响应。
答案 0 :(得分:0)
您可以尝试使用此代码进行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获取更多帮助