问题描述
新浪微博java sdk如何获得一条评论的ID号
解决方案
调用GetCategoryFeatures获取可用的Item Condition Definition,然后将某个Condition ID传递给AddItem或ReviseItem call 下面例程基于Java SDK调用GetCategoryFeatures。指定为US站点上编号63861的Categorypackage 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 Definitionf如下所示: 1000 - New with tags 1500 - New without tags 1750 - New with defects 3000 - Pre-owned 选择某个condition ID,如"New with tags"。在 AddItem或ReviseItem调用中设置condtionID为 "1000"AddItemCall request = new AddItemCall(createApiContext()); ItemType item = new ItemType(); item.setConditionID(1000);...request.setItem(item); request.addItem();...资料地址http://www.ebay.cn/show.php?contentid=4617
解决方案二:
可以根据一条微博取得他下面的所有评论,然后你自己过滤取得想要的那条评论就可以了http://open.weibo.com/wiki/2/comments/showJAVA SDK 提供的weibo4j代码 有获取指定微博下的所有评论http://code.google.com/p/weibo4j/package weibo4j.examples.comment;import weibo4j.Comments;import weibo4j.Weibo;import weibo4j.examples.oauth2.Log;import weibo4j.model.Comment;import weibo4j.model.CommentWapper;import weibo4j.model.WeiboException;public class GetCommentById {public static void main(String[] args) {String access_token = args[0];Weibo weibo = new Weibo();weibo.setToken(access_token);String id = args[1];Comments cm =new Comments();try {CommentWapper comment = cm.getCommentById(id);for(Comment c : comment.getComments()){Log.logInfo(c.toString());}System.out.println(comment.getTotalNumber());System.out.println(comment.getNextCursor());System.out.println(comment.getNextCursor());System.out.println(comment.getHasvisible());} catch (WeiboException e) {e.printStackTrace();}}}