博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ebay 如何获取用户token
阅读量:6856 次
发布时间:2019-06-26

本文共 4402 字,大约阅读时间需要 14 分钟。

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.0mvn install:install-file -Dfile=C:\ebay\ebaysdkjava1055\lib\ebaysdkcore.jar -DgroupId=com.ebay -DartifactId=ebaysdkcore -Dpackaging=jar -DgeneratePom=true -Dversion=1.7.0mvn 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

结果如下图所示:

2018-05-30T08:26:55.783Z
Success
1059
E1059_CORE_APISIGNIN_18690974_R1
xxxxxx
2019-11-21T08:25:46.000Z

 

参考资料:

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

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

 

转载于:https://www.cnblogs.com/mengjianzhou/p/9111907.html

你可能感兴趣的文章
【译】RAID的概念和RAID对于SQL性能的影响
查看>>
Python介绍
查看>>
SOAP Webservice和RESTful Webservice
查看>>
Photoshop通道抠出散乱的儿童头发
查看>>
Navi.Soft31.阅读导航
查看>>
Magcodes.WeiChat——通过CsvFileResult以及DataAnnotations实现导出CSV文件
查看>>
裁切数据库
查看>>
Android Gradle 自定义Task详解二:进阶
查看>>
关于卷积的一个血腥的讲解,看完给跪了
查看>>
部署 instance 到 OVS vlan100 - 每天5分钟玩转 OpenStack(138)
查看>>
SQLyog图形化l数据库的操作和学习
查看>>
93.3. jinfo - Configuration Info
查看>>
解读基础设施即代码
查看>>
不容错过的2017数据科学15大热门GitHub项目
查看>>
2.4. 编译用于Tomcat的 War
查看>>
IPA提交APPStore问题记录(二)iOS10
查看>>
Spring Bean装配&#183;Aware&#183;Resource
查看>>
关于MYSQL 5.7 新连接建立流程源码接口(和5.6不同)
查看>>
8.3. 数据库与外界文件
查看>>
10g 一主多备的搭建技巧
查看>>