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

ebay 如何获取用户token的更多相关文章

  1. 融云SDK:获取用户Token的方法

    融云SDK查看ServerAPI里面有个获取Token的方法,本以为只要传三个参数就可以.后来发现,在请求头有几个必须要传的参数,否则服务器返回401(未授权).拿获取Token接口为例子 如图所示, ...

  2. .NET微信开发通过Access Token和OpenID获取用户信息

    本文介绍如何获得微信公众平台关注用户的基本信息,包括昵称.头像.性别.国家.省份.城市.语言. 本文的方法将囊括订阅号和服务号以及自定义菜单各种场景,无论是否有高级接口权限,都有办法来获得用户基本信息 ...

  3. OAuth2.0 微博登陆网站功能的实现(一)获取用户授权及令牌 Access Token

    在登陆一些网站的时候,可以选择登陆方式为第三方登陆,例如微博登陆,以爱奇艺为例,进入首页,点击 ”登陆“,会弹出登录框: 除了本站登陆外,还可以选择其他第三方登陆,比如微博登陆.QQ 登陆.微信登陆等 ...

  4. 后台获取用户登录token 和获取前端参数方法

    //获取request请求中所有参数 Enumeration<String> names = request.getParameterNames(); HashMap<String, ...

  5. 再谈Token认证,如何快速方便获取用户信息

    前面我写了一篇<Token认证,如何快速方便获取用户信息>的文章,引起了各位读者的积极参与,除了文章中我提出的三种方式,各位读者大佬们也贡献了其他多种实现方式. 今天决定基于大家提供的思路 ...

  6. Token认证,如何快速方便获取用户信息

    背景 我们有一个Web项目,这个项目提供了很多的Rest API.也做了权限控制,访问API的请求必须要带上事先认证后获取的Token才可以. 认证的话就在Filter中进行的,会获取请求的Token ...

  7. Spring Cloud云架构 - SSO单点登录之OAuth2.0 根据token获取用户信息(4)

    上一篇我根据框架中OAuth2.0的使用总结,画了SSO单点登录之OAuth2.0 登出流程,今天我们看一下根据用户token获取yoghurt信息的流程: /** * 根据token获取用户信息 * ...

  8. 整合spring cloud云架构 - 根据token获取用户信息

    根据用户token获取yoghurt信息的流程: /** * 根据token获取用户信息 * @param accessToken * @return * @throws Exception */ @ ...

  9. jwt token校验获取用户数据

    /** * 用户登录成功之后,获取用户信息 * 1.获取用户id * 2.根据id查询用户 * 3.构建返回值对象 * 4.返回数据 * @return */@RequestMapping(value ...

随机推荐

  1. libpcap 中调用ctime()时警告提示:

    warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]    ...

  2. RAR去除广告

    现在注册已经不能去掉广告了,给你一个100%有效的办法(##此教程已更新,最新的winrar5.5同样适用,但是多了一个步骤) 电脑桌面新建一个txt文件,重命名为“rarreg.key” 2. 将. ...

  3. Java多线程系列五——列表类

    参考资料: http://xxgblog.com/2016/04/02/traverse-list-thread-safe/ 一些列表类及其特性  类 线程安全 Iterator 特性 说明 Vect ...

  4. 《Effective C++》笔记:III(转载)

    转自:http://www.cnblogs.com/destino74/p/3960802.html 条款5:Know what functions C++ silently writes and c ...

  5. 关于file文件操作的头文件 【LINUX】 (转载)

    转自:http://blog.csdn.net/figo77ll/article/details/3156052 Linux下如果要对文件进行读取访问,需要包含至少以下两个头文件: #inlcude ...

  6. bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚【dp+线段树】

    设f[i]为i时刻最小花费 把牛按l升序排列,每头牛能用f[l[i]-1]+c[i]更新(l[i],r[i])的区间min,所以用线段树维护f,用排完序的每头牛来更新,最后查询E点即可 #includ ...

  7. (数论)51NOD 1079 中国剩余定理

    一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K.例如,K % 2 = 1, K % 3 = 2, K % 5 = 3.符合条件的最小的K = 23.   Input 第1行:1个数 ...

  8. 429c Leha and Function

    题目 解题报告 F(n, k)是在集合{1, 2, 3, ..., n}中所有的具有k个元素的子集中分别取最小值,相加后的期望. 例如:要求F(4, 2),根据定义有{1, 2}, {1, 3}, { ...

  9. CSS之选择符、链接、盒子模型、显示隐藏元素

    <html> <head> <meta charset="utf-8"> <title>选择符.链接.盒子模型.显示隐藏元素< ...

  10. 264 Ugly Number II 丑数 II

    编写程序找第 n 个丑数.丑数就是只包含质因子 2, 3, 5 的正整数.例如, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 就是前10个丑数.注意:1. 1 一般也被当做丑数2. ...