使用 OAuth 2.0 授权调用Content API for Shopping产品推送

private static ShoppingContent initializeContentService() throws IOException, GeneralSecurityException {
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
        FileInputStream credentialsStream = new FileInputStream(GOOGLE_JSON_PATH);
        GoogleCredentials googleCredentials = GoogleCredentials.fromStream(credentialsStream).createScoped(ShoppingContentScopes.all());

        return new ShoppingContent
                .Builder(httpTransport, jsonFactory, new HttpCredentialsAdapter(googleCredentials))
                .setApplicationName("Merchant Center")
                .build();
    }
private static final String GOOGLE_JSON_PATH = "/gsdata/tokens/gs-jj-335906-808f447c80b6.json";
GOOGLE_JSON_PATH :密钥文件路径,gs-jj-335906-808f447c80b6.json创建服务账号Google生成密钥文件

Google服务帐号访问 Content API for Shopping 文档路径

1.创建产品

public static String sampleProductId(String contentLanguage, String targetCountry, String offerId) {
        return CHANNEL + ":" + contentLanguage + ":" + targetCountry + ":" + offerId;
    }



List<ProductShipping> productShippingList = new ArrayList<>();
        ProductShipping productShipping = new ProductShipping();
        productShipping.setCountry("US");
        productShipping.setPrice(new Price().setValue("0.00").setCurrency("USD"));
        productShippingList.add(productShipping);

        Product product = new Product()
                .setId(sampleProductId("en", "US", "111111"))
                .setOfferId("111111")
                .setKind("content#product")//固定为content#product
                .setColor("custom colors")//颜色
                .setSizes(Arrays.asList("one size"))//尺寸
                .setTitle("title")
                .setDescription("description")
                .setGender("unisex")
                .setGoogleProductCategory("Apparel & Accessories Handbag & Wallet Accessories Keychains")//google产品分类
                .setGtin(StringUtils.isNotEmpty(customProduct.getGtin()) ? customProduct.getGtin() : "")
                .setLink("https://" +  url  + customProduct.getProductRouting())
                .setBrand("xxxx")
                .setImageLink("product img")
                .setChannel(CHANNEL)
                .setContentLanguage("en")
                .setTargetCountry("US")
                .setAvailability("in stock")//库存,in stock表达有库存
                .setCondition("new")
                .setShipping(productShippingList)//多个国家,配置多个country设置不同
                .setPrice(new Price().setValue("123").setCurrency("USD"));
        ShoppingContent contentService = initializeContentService();
        contentService.products().insert(MERCHANT_ID, product).execute();
private static final String CHANNEL = "online";

id规则:channel:contentLanguage:targetCountry:offerId

Google Products API

产品参数详情链接

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值