/*
© 2009-2013 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/
import com.ebay.sdk.*;
import com.ebay.soap.eBLBaseComponents.*;
import com.ebay.sdk.pictureservice.*;
import com.ebay.sdk.pictureservice.eps.*;
public class AppUploadpicutre {
private static String m_serverURL="https://api.ebay.com/ws/api.dll";
private static String m_token="YOUR USER TOKEN";
private static String m_outputFile;
private static String imageFileName1="";
private static String imageFileName2="";
private static String[] pictureFiles = {imageFileName1,imageFileName2};
private static String apiVersion="833";
public static void main(String[] args) {
try {
// apiContext object
ApiContext apiContext = new ApiContext();
// Create credential object.
ApiCredential cred = apiContext.getApiCredential();
cred.seteBayToken(m_token);
//enable logging ApiLogging logging = new ApiLogging();
apiContext.setApiLogging(logging);
// set EpsServerUrl apiContext.setEpsServerUrl(m_serverURL);
apiContext.setSite(SiteCodeType.US);
apiContext.setWSDLVersion(apiVersion);
//create PictureService object
PictureService pictureService=eBayPictureServiceFactory.getPictureService(apiContext);
//build a PictureInfo array for holding multiple picture file names
PictureInfo[] piList = new PictureInfo[pictureFiles.length];
for(int i = 0; i < pictureFiles.length; i ++) {
piList[i] = new PictureInfo();
piList[i].setPictureFilePath(pictureFiles[i]);
}
int uploads = pictureService.uploadPictures (PhotoDisplayCodeType.NONE,piList);
if (uploads !=0 ) {
for(int i = 0; i < piList.length; i ++ ) {
String errorMsg= piList[i].getErrorMessage() ;
if (piList[i].getReponse().getAck().compareTo(AckCodeType.FAILURE)==0){
System.out.print( piList[i].getErrorType() + " | " + errorMsg ) ;
}else {
//http://developer.ebay.com/devzone/xml/docs/Reference/eBay/UploadSiteHostedPictures.html#Response.SiteHostedPictureDetails.FullURL
// print out the generated image URL that can be used to associate with an item
System.out.println (piList[i].getReponse().getSiteHostedPictureDetails().getFullURL());
if (errorMsg !=null && errorMsg.length() >0) {
System.out.print( piList[i].getErrorType() + " | " + errorMsg ) ;
};
}
}
}
} catch(Exception e) { //handle exception here }
}
}
|