Initial setup
创建 GMC 账户 注册 GMC .
配置以下帐户设置:
在 GMC 中,找到商家 ID,即页面右上角帐户电子邮件地址上方的数字。
在 API 资源管理器 设置
products.list
- 输入
merchantId
. 所有其他请求参数都是可选的。 - 在
Credentials
那里,选Google OAuth 2.0
andAPI
key - 点击
Execute
按钮 - 如果出现提示,请使用与您的 GMC 帐户关联的 Google 帐户登录
- 输入
如果设置正确,则会返回 200 状态, 但如果还没有创建商品的话, 则products.list
方法 不会返回任何商品.添加以后则会显示如下的返回值
API
products.list request
cCURL
1
2
3
4
5 curl \
'https://shoppingcontent.googleapis.com/content/v2.1/536169960/products?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressedHTTP
1
2
3
4 GET https://shoppingcontent.googleapis.com/content/v2.1/536169960/products?key=[YOUR_API_KEY]
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/jsonJAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for content.products.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/content"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("YOUR_API_KEY");
return gapi.client.load("https://shoppingcontent.googleapis.com/$discovery/rest?version=v2.1")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.content.products.list({
"merchantId": 536169960
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
products.list response
application/json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 {
"kind": "content#productsListResponse",
"resources": [
{
"kind": "content#product",
"id": "online:ja:JP:jmanxfrv",
"offerId": "jmanxfrv",
"title": "ps5",
"description": "play station 5",
"imageLink": "https://www.dotenn.com/2022/01/13/4948872415026/",
"contentLanguage": "ja",
"targetCountry": "JP",
"channel": "online",
"availability": "in stock",
"brand": "sony",
"condition": "new",
"gtin": "4948872415026",
"price": {
"value": "120000.00",
"currency": "JPY"
}
}
]
}