1. 首先 配置环境加载依赖的ebay SDK

下载地址 https://go.developer.ebay.com/ebay-sdks

需要在本地仓库安装下面的jar

mvn install:install-file -Dfile=C:\ebay\ebaysdkjava1055\lib\ebaycalls.jar -DgroupId=com.ebay -DartifactId=ebaycalls -Dpackaging=jar -DgeneratePom=true -Dversion=1.7.0
mvn install:install-file -Dfile=C:\ebay\ebaysdkjava1055\lib\ebaysdkcore.jar -DgroupId=com.ebay -DartifactId=ebaysdkcore -Dpackaging=jar -DgeneratePom=true -Dversion=1.7.0
mvn install:install-file -Dfile=C:\ebay\ebaysdkjava1055\lib\helper.jar -DgroupId=com.ebay -DartifactId=helper -Dpackaging=jar -DgeneratePom=true -Dversion=1.7.0、

2. 获取sessionId

import com.ebay.sdk.ApiAccount;
import com.ebay.sdk.ApiContext;
import com.ebay.sdk.call.FetchTokenCall;
import com.ebay.sdk.helper.ConsoleUtil; import java.io.IOException;
public class EbayGetSessionIdController { public static void main(String[] args) {
try {
// Instantiate ApiContext and initialize with token and Trading API URL
ApiContext apiContext = getApiContext();
obtainSessionID(apiContext);
obtainUserToken(apiContext);
} //try
catch(Exception e) {
System.out.println("Fail to get sessionID.");
e.printStackTrace();
}
} private static void obtainUserToken(ApiContext apiContext) throws Exception {
FetchTokenCall fetchTokenCall = new FetchTokenCall(apiContext);
fetchTokenCall.setSessionID("#{sessionId}");
String token = fetchTokenCall.fetchToken();
System.out.println("token :"+token);
} private static void obtainSessionID(ApiContext apiContext) throws Exception {
//Create call object and execute the call
GetSessionIDCall apiCall = new GetSessionIDCall(apiContext);
apiCall.setRuName("#{ru_name}");
String sessionID = apiCall.getSessionID();
//Handle the result returned
System.out.println("sessionID : " + sessionID);
String url = "https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&runame=#{ru_name}&SessID=" + sessionID;
System.out.println("url: "+url);
openBrowser(url);
} public static boolean openBrowser(String url) {
if (url == null) return false;
String[] unixBrowser = new String[] { "google-chrome", "firefox" };
boolean success = false;
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
try {
Runtime.getRuntime().exec(
new String[] { "rundll32.exe", "url.dll,FileProtocolHandler", url });
success = true;
} catch (Exception e) {
}
} else {
for (int i = 0; i < unixBrowser.length; ++i)
try {
Runtime.getRuntime().exec(new String[] { unixBrowser[0], url });
success = true;
break;
} catch (Exception e) {
}
}
return success;
} // Initializes ApiContext with token and eBay API server URL
private static ApiContext getApiContext() throws IOException { String input;
ApiContext apiContext = new ApiContext();
//set Api Server Url
input = ConsoleUtil.readString("Enter eBay SOAP server URL (e.g., https://api.ebay.com/wsapi): ");
apiContext.setApiServerUrl(input);
ApiAccount apiAccount = new ApiAccount();
String appId = "your app id";
String devId = "your deveoper id";
String certId = "your Cert ID ";
apiAccount.setApplication(appId);
apiAccount.setDeveloper(devId);
apiAccount.setCertificate(certId);
apiContext.getApiCredential().setApiAccount(apiAccount);
return apiContext;
} //getApiContext
}

上面有4个参数需要获取

appId、devId、certId、ru_name

登录ebay deveopers program后,在首页->My Account->Application Keys页面下,可以看到AppId 、DevId、CertId

然后 点击上图中的User Token

上图中拿到RuName

3. 获得相应的use token

结果如下图所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<FetchTokenResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2018-05-30T08:26:55.783Z</Timestamp>
<Ack>Success</Ack>
<Version>1059</Version>
<Build>E1059_CORE_APISIGNIN_18690974_R1</Build>
<eBayAuthToken>xxxxxx</eBayAuthToken>
<HardExpirationTime>2019-11-21T08:25:46.000Z</HardExpirationTime>
</FetchTokenResponse>
</soapenv:Body>
</soapenv:Envelope>

参考资料:

https://blog.csdn.net/sunwukong54/article/details/12092187

http://developer.ebay.com/devzone/xml/docs/howto/tokens/gettingtokens.html

最新文章

  1. 2000条你应知的WPF小姿势 基础篇&lt;78-81 Dialog/Location/WPF设备无关性&gt;
  2. monggodb学习系列:1,mongodb入门
  3. [.net 面向对象编程基础] (1) 开篇
  4. SqlServer链接MySql操作步骤
  5. 自定义UICollectionViewLayout之瀑布流
  6. iOS 原生地图(MapKit、MKMapView)轨迹渐变
  7. Java条形码生成方案及二维码要点
  8. 【稳定婚姻问题】【HDU1435】【Stable Match】
  9. require.js(浅聊)
  10. php数组合并,反转,去重,添加元素等;
  11. Mac入门——快捷键
  12. ngnix 是什么
  13. Linux命令之常用篇
  14. gitlab备份
  15. ros的一些设置
  16. Angular CLI 安装和使用以及安装失败的解决方法
  17. Jersey入门三:创建一个JavaEE的Web项目
  18. Apache POI – Reading and Writing Excel file in Java
  19. 【Android】5.0 第5章 常用基本控件--本章示例主界面
  20. MongoDB-2:MongoDB添加、删除、修改

热门文章

  1. 【转载】Java - Wait &amp; Notify
  2. 在Linux环境下使用OpenSSL对消息和文件进行加密(转载)
  3. 树网的核 2007年NOIP全国联赛提高组(floyed)
  4. JS 九宫格算法 用原生js实现
  5. 洛谷 P1880 [NOI1995]石子合并
  6. srand()
  7. ACM_Plants vs. Zombies(一元一次方程)
  8. 371 Sum of Two Integers 两整数之和
  9. 常见Z纯CSS小样式合集(三角形)
  10. 在linux下运行mongodb