列出 CSS 商品
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用此示例列出 CSS 商品。
cURL
curl --location 'https://css.googleapis.com/v1/accounts/1234567/cssProducts' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_TOKEN>'
Java
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shopping.css.samples.v1.cssproducts;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.css.v1.CssProduct;
import com.google.shopping.css.v1.CssProductsServiceClient;
import com.google.shopping.css.v1.CssProductsServiceClient.ListCssProductsPagedResponse;
import com.google.shopping.css.v1.CssProductsServiceSettings;
import com.google.shopping.css.v1.ListCssProductsRequest;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to list CSS Products for a given Account */
public class ListCssProducts {
private static String getParent(String domainId) {
return String.format("accounts/%s", domainId);
}
private static String getName(String domainId, String productId) {
return String.format("accounts/%s/cssProducts/%s", domainId, productId);
}
public static void listCssProducts(Config config) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
CssProductsServiceSettings cssProductsServiceSettings =
CssProductsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String parent = getParent(config.getDomainId().toString());
try (CssProductsServiceClient cssProductsServiceClient =
CssProductsServiceClient.create(cssProductsServiceSettings)) {
ListCssProductsRequest request =
ListCssProductsRequest.newBuilder().setParent(parent).build();
System.out.println("Sending ListCssProducts request");
ListCssProductsPagedResponse response = cssProductsServiceClient.listCssProducts(request);
System.out.println("Retrieved CssProduct Names: ");
int count = 0;
// Iterates over all rows in all pages and prints the element in each row
for (CssProduct element : response.iterateAll()) {
System.out.println(element);
count++;
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
final Config config = Config.load();
listCssProducts(config);
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThis code sample demonstrates how to list CSS Products for a given Account using the Content API for Shopping.\u003c/p\u003e\n"],["\u003cp\u003eIt provides examples in both cURL and Java, showing how to authenticate and send requests to the CSS Products service.\u003c/p\u003e\n"],["\u003cp\u003eThe Java example iterates through all pages of results and prints the details of each CSS Product.\u003c/p\u003e\n"]]],[],null,["# List CSS Products\n\nUse this sample to list CSS Products. \n\n### cURL\n\n curl --location 'https://css.googleapis.com/v1/accounts/1234567/cssProducts' \\\n --header 'Content-Type: application/json' \\\n --header 'Authorization: Bearer \u003cAPI_TOKEN\u003e'\n\n### Java\n\n // Copyright 2023 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.css.samples.v1.cssproducts;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.css.v1.CssProduct;\n import com.google.shopping.css.v1.CssProductsServiceClient;\n import com.google.shopping.css.v1.CssProductsServiceClient.ListCssProductsPagedResponse;\n import com.google.shopping.css.v1.CssProductsServiceSettings;\n import com.google.shopping.css.v1.ListCssProductsRequest;\n import shopping.css.samples.utils.Authenticator;\n import shopping.css.samples.utils.Config;\n\n /** This class demonstrates how to list CSS Products for a given Account */\n public class ListCssProducts {\n\n private static String getParent(String domainId) {\n return String.format(\"accounts/%s\", domainId);\n }\n\n private static String getName(String domainId, String productId) {\n return String.format(\"accounts/%s/cssProducts/%s\", domainId, productId);\n }\n\n public static void listCssProducts(Config config) throws Exception {\n GoogleCredentials credential = new Authenticator().authenticate();\n\n CssProductsServiceSettings cssProductsServiceSettings =\n CssProductsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n String parent = getParent(config.getDomainId().toString());\n\n try (CssProductsServiceClient cssProductsServiceClient =\n CssProductsServiceClient.create(cssProductsServiceSettings)) {\n\n ListCssProductsRequest request =\n ListCssProductsRequest.newBuilder().setParent(parent).build();\n\n System.out.println(\"Sending ListCssProducts request\");\n ListCssProductsPagedResponse response = cssProductsServiceClient.listCssProducts(request);\n System.out.println(\"Retrieved CssProduct Names: \");\n\n int count = 0;\n\n // Iterates over all rows in all pages and prints the element in each row\n for (CssProduct element : response.iterateAll()) {\n System.out.println(element);\n count++;\n }\n System.out.print(\"The following count of elements were returned: \");\n System.out.println(count);\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n final Config config = Config.load();\n\n listCssProducts(config);\n }\n } \n https://github.com/googleads/comparison-shopping-service-api-samples/blob/2f511c3ca413bdbd497f89ae7468b3191dafaa6d/java/src/main/java/shopping/css/samples/v1/cssproducts/ListCssProducts.java"]]