eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>如何使用Java SDK为指定的category刊登设置Item Condition

技术文档

问题
如何使用Java SDK为指定的category刊登设置Item Condition
解答
0
人觉得答案有帮助)
通过呼叫GetCategoryFeatures来获取可用的Item condition值,在使用AddItemReviseItem时将指定的ConditionID传入

以下为一个sample code,使用Java SDK呼叫GetCategoryFeatures。我们制定category为US站点的 63861: 

package com.ebay.test;
import com.ebay.sdk.ApiAccount;
import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.ApiLogging;
import com.ebay.sdk.CallRetry;
import com.ebay.sdk.call.GetCategoryFeaturesCall;
import com.ebay.soap.eBLBaseComponents.CategoryFeatureType;
import com.ebay.soap.eBLBaseComponents.ConditionEnabledCodeType;
import com.ebay.soap.eBLBaseComponents.ConditionType;
import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
import com.ebay.soap.eBLBaseComponents.SiteCodeType;
public class AppGetCategoryFeatures {
public static ApiContext createApiContext() {
ApiContext apiContext = new ApiContext();
ApiLogging apiLogging = new ApiLogging();
apiContext.setApiLogging(apiLogging);
CallRetry cr = new CallRetry();
cr.setMaximumRetries(3);
cr.setDelayTime(1000); // Wait for one second between each retry-call.
String[] apiErrorCodes = new String[] { "502" };
// Set trigger exceptions for CallRetry.
cr.setTriggerApiErrorCodes(apiErrorCodes);
// Build a dummy SdkSoapException so that we can get its Class.
Class[] tcs = new Class[] { com.ebay.sdk.SdkSoapException.class };
cr.setTriggerExceptions(tcs);
apiContext.setCallRetry(cr);
apiContext.setTimeout(180000);
ApiCredential cred = new ApiCredential();
apiContext.setApiServerUrl("https://api.sandbox.ebay.com/wsapi");
// apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
ApiAccount ac = cred.getApiAccount();
ac.setApplication(YOUR-APPID);
ac.setDeveloper(YOUR-DEVID);
ac.setCertificate(YOUR-CERTID);
cred.seteBayToken(YOUR-TOKEN);
apiContext.setApiCredential(cred);
return apiContext;
}
private static GetCategoryFeaturesCall getCatFeature(String categoryId, SiteCodeType site) {
GetCategoryFeaturesCall request = new GetCategoryFeaturesCall(
createApiContext());
request.setSite(site);
request.setDetailLevel(new DetailLevelCodeType[] { DetailLevelCodeType.RETURN_ALL });
request.setCategoryID(categoryId);
request.setOutputSelector(new String[] {
"Category.ConditionEnabled",
"Category.ConditionValues.Condition.ID",
"Category.ConditionValues.Condition.DisplayName" });
try {
request.getCategoryFeatures();
} catch (Exception e) {
e.printStackTrace();
}
return request;
}
public static void main(String[] args) {
GetCategoryFeaturesCall cf = getCatFeature("63861", SiteCodeType.US);
/*
* Since we call GetCategoryFeatures for a specified category, so we
* just get the first category element here
*/
CategoryFeatureType feature = cf.getReturnedCategory()[0];
/*
* If condition Enabled is disabled, then DO NOT pass conditionID in
* AddItem or ReviseItem for this category
*/
if (feature.getConditionEnabled().equals(ConditionEnabledCodeType.ENABLED)) {
for (ConditionType con : feature.getConditionValues().getCondition())
System.out.println(con.getID() + " - " + con.getDisplayName());
}
}
}



运行该程序,将可以看到该category中可用的condition ID:

 
1000 - New with tags
1500 - New without tags
1750 - New with defects
3000 - Pre-owned

选择你需要的condition ID,这里我们选择 "New with tags"。因此我们将condtionID "1000" 传入AddItem


...
AddItemCall request = new AddItemCall(createApiContext());
ItemType item = new ItemType();
item.setConditionID(1000);
...
request.setItem(item);
request.addItem();
...

 

 
版本信息

 

以上代码基于以下版本信息:

API Schema Version
673
Java SDK Version
eBay Java SDK v673 Full Release (for JDK 1.5 and 1.6)

答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题