how can I use GetMyMessageCall to get the messages in MyeBay
Detailed Description
GetMyMessages does not have data filters for reducing the volume of the response so that we suggest you follow the GetMyMessages 'Controlling the Volume of the Response' guide to control the volume of the response. The sample project below illustrates how to use DetailLevel filter to accomplish the goal .
1. Make GetMyMessages call with DetailLevelCodeType.ReturnHeaders to get a complete list of alert and message headers with their corresponding alert ID and message ID values.
2. If there are Alerts or Messages, make GetMyMessages call again with DetailLevelCodeType.ReturnMessages to retrieve specific alerts and specific messages. Keep in mind you can only specify ten AlertIDs and ten MessageIDs at a time.
You need to include the attached RequestHeaderParam.java source file and the request_param.properties properties file in order to run this sample as a standalone application.
NOTE. This sample only retrieves Messages but by taking the retrieveMessages() function as a reference, you can easily add a functionality to obtain Alerts .
/** */ public class AppGetMyMessage { private String configFile= "request_header_param.properties"; private ApiContext apiContext; private boolean _isCore =true; private ApiCall _apiCall;
/** Creates a new instance of AppGetMyMessage */ public AppGetMyMessage() { RequestHeaderParam requestHeaderParam = new RequestHeaderParam(); apiContext = requestHeaderParam.createContext(configFile); apiContext.setErrorLanguage("en_US"); //Enable logging ApiLogging logging = new ApiLogging(); apiContext.setApiLogging(logging); }
public static void main(String [] args){ AppGetMyMessage agmm = new AppGetMyMessage(); GetMyMessagesCall apiCall = new GetMyMessagesCall(agmm.apiContext); DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
// Using DetailLevel.ReturnHeaders filter // to get a complete list alert and message headers with their corresponding alert ID and message ID values. DetailLevelCodeType.ReturnHeaders, }; apiCall.setDetailLevel(detailLevels); try{ apiCall.getMyMessages();
// If there are Messages if (msgs !=null){ int page=1, totalPages=0; // retrieve ten messages at a time ( a page) if (msgs.length%10 !=0 ){ totalPages = msgs.length/10 + 1; }else { totalPages= msgs.length; } // make second GetMyMessages call agmm .retrieveMessages(apiCall,page,totalPages,msgs); }
public void retrieveMessages(GetMyMessagesCall api, int page,int totalPages,MyMessagesMessageType[] msgs){ MyMessagesMessageIDType[] msgIds =null; int start =0, end =0;
start = (page-1)*10; if (totalPages ==1 || page==totalPages) { end = msgs.length; } else end = (page*10) ; msgIds = new MyMessagesMessageIDType[end-start];
for (int i=start; i<end; i++){ if ( msgs[i] !=null){ for ( int j=0; j<(end-start); j++){ msgIds[j] = msgs[i].getMessageID(); } } } DetailLevelCodeType[] detail = new DetailLevelCodeType[] { // retrieve specific ten alerts and ten specific messages at a time //with DetailLevel.ReturnMessages DetailLevelCodeType.ReturnMessages, }; api.setDetailLevel(detail); api.setMessageIDs(msgIds); try{ api.getMyMessages();
// make another GetMyMessage call when there are more than ten messages if (page<totalPages){ retrieveMessages(api, ++page,totalPages,msgs); } }catch (Exception e) { } }