eBay API,从数字站点ID获取全局ID [英] eBay API, get globalID from numerical Site ID
问题描述
正如标题所说,我有数字站点ID,我需要一种方法来获取相应的GlobalId。
我知道有匹配表
https:/ /developer.ebay.com/DevZone/merchandising/docs/CallRef/Enums/GlobalIdList.html
https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html
但我需要一种编程方式来完成它。 您的三个选项:
哈希映射实现
import java.util.HashMap;
public class Mappings {
public static void main(String [] args){
HashMap myMap = new HashMap< Integer,String>();
myMap.put(0,EBAY-US);
myMap.put(2,EBAY-ENCA);
myMap.put(3,EBAY-GB);
myMap.put(15,EBAY-AU);
// ...
System.out.println(给定ID 15,它对应的全局ID是:+ myMap.get(15));
$ b SQL表实现
//步骤1.导入所需的软件包
import java.sql。*;
public class JDBCExample {
// JDBC驱动程序名称和数据库URL
static final String JDBC_DRIVER =com.mysql.jdbc.Driver;
static final String DB_URL =jdbc:mysql:// localhost / STUDENTS;
//数据库凭证
static final String USER =username;
static final String PASS =password;
public static void main(String [] args){
Connection conn = null;
Statement stmt = null;
尝试{
//步骤2:注册JDBC驱动程序
Class.forName(com.mysql.jdbc.Driver);
//第3步:打开一个连接
System.out.println(连接到选定的数据库...);
conn = DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println(已连接数据库成功...);
//第4步:执行查询
System.out.println(将记录插入表中...);
stmt = conn.createStatement();
String sql =INSERT INTO Mappings+
VALUES(0,'EBAY-US');
stmt.executeUpdate(sql);
sql =INSERT INTO Mappings+
VALUES(2,'EBAY-ENCA');
stmt.executeUpdate(sql);
sql =INSERT INTO Mappings+
VALUES(3,'EBAY-GB');
stmt.executeUpdate(sql);
sql =INSERT INTO Mappings+
VALUES(15,'EBAY-AU');
stmt.executeUpdate(sql);
System.out.println(在表格中插入记录...);
sql =SELECT siteID,globalID FROM Mappings;
ResultSet rs = stmt.executeQuery(sql);
$ b $ //步骤5:从结果集中提取数据
while(rs.next()){
//按列名称检索
int siteId = rs。 getInt( 的siteID);
int globalId = rs.getInt(globalID);
//显示值
System.out.print(siteId:+ siteId);
System.out.print(,globalId:+ globalId);
}
rs.close();
} catch(SQLException se){
//处理JDBC错误
se.printStackTrace();
} catch(Exception e){
//处理Class.forName
的错误e.printStackTrace();
} finally {
// finally用来关闭资源
try {
if(stmt!= null)
conn.close();
} catch(SQLException se){
} //什么也不做
try {
if(conn!= null)
conn.close();
} catch(SQLException se){
se.printStackTrace();
} // end finally try
} // end try
System.out.println(Goodbye!);
} // end main
} // end JDBCExample
和服实施
如果您不希望为本地存储站点ID <=>全局ID映射(如techcrunch文章中所述) 和服是一个更智能的网络刮板,让你API-ify网络,无需代码,:
<$与Kimono一样,最终目标是简化数据提取,以便任何人都可以管理它。
然后Kimono的学习算法将构建一个数据模型,其中包含您选择
的项目。
由于和服的网站进入提及:
在几秒钟内将网站从您的浏览器转变为结构化的API。
As the title says, I have the numerical Site ID, I need a way to get the corresponding GlobalId.
I know there are tables with matches
https://developer.ebay.com/DevZone/merchandising/docs/CallRef/Enums/GlobalIdList.html
https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html
but I need a programmatic way to do it.
Your three options:
Hash Map implementation
import java.util.HashMap;
public class Mappings{
public static void main(String []args){
HashMap myMap = new HashMap<Integer, String>();
myMap.put(0, "EBAY-US");
myMap.put(2, "EBAY-ENCA");
myMap.put(3, "EBAY-GB");
myMap.put(15, "EBAY-AU");
//...
System.out.println("Given ID 15, it's corresponding Global ID is: " + myMap.get(15));
}
}
SQL Table implementation
//STEP 1. Import required packages
import java.sql.*;
public class JDBCExample {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
//STEP 4: Execute a query
System.out.println("Inserting records into the table...");
stmt = conn.createStatement();
String sql = "INSERT INTO Mappings " +
"VALUES (0, 'EBAY-US')";
stmt.executeUpdate(sql);
sql = "INSERT INTO Mappings " +
"VALUES (2, 'EBAY-ENCA')";
stmt.executeUpdate(sql);
sql = "INSERT INTO Mappings " +
"VALUES (3, 'EBAY-GB')";
stmt.executeUpdate(sql);
sql = "INSERT INTO Mappings " +
"VALUES (15, 'EBAY-AU')";
stmt.executeUpdate(sql);
System.out.println("Inserted records into the table...");
sql = "SELECT siteID, globalID FROM Mappings";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int siteId = rs.getInt("siteID");
int globalId = rs.getInt("globalID");
//Display values
System.out.print("siteId: " + siteId);
System.out.print(", globalId: " + globalId);
}
rs.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}// do nothing
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end JDBCExample
Kimono implementation
If you don't want to have local storage for the Site ID <=> Global ID mappings, as mentioned in the techcrunch article, "Kimono Is A Smarter Web Scraper That Lets You "API-ify" The Web, No Code Required,":
With Kimono, the end goal is to simplify data extraction so that anyone can manage it.
Then Kimono’s learning algorithm will build a data model involving the items you’ve
selected.
As Kimono's website goes onto mention:
Turn websites into structured APIs from your browser in seconds.
这篇关于eBay API,从数字站点ID获取全局ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!