import java.math.BigInteger
import java.util
import java.util.concurrent.atomic.AtomicLong
import com.ebctech.PAGFeed.updater.Authorization
import com.google.api.services.content.model.{Product, ProductsCustomBatchRequest, ProductsCustomBatchRequestEntry}
import net.sf.cglib.core.KeyFactory
import scala.collection.mutable
import scala.io.Source
object ProductUpdtaeForParticularField {
private val merchantId = new BigInteger("MerchantId")
private val file = "/home/spineor/40TocheckParticularId"
val batchId = new AtomicLong()
val particularId: mutable.Map[String, List[String]] = mutable.Map[String, List[String]]()
def loadCsv(File: String): mutable.Map[String,List[String]] = {
for (line <- Source.fromFile(File).getLines) {
val cols = line.split("\\^").toList
particularId += cols.head -> cols
}
particularId
}
def main(args: Array[String]): Unit = {
val service = Authorization.getShoppingContent
val source: mutable.Map[String, List[String]] = loadCsv(file)
var sourceId = source.map(i => (s"online:en:US:${i._1}", i._2))
var i = 0
while(i < sourceId.size){
val request = service.products().custombatch(createBatch(sourceId.take(20)))
val result = request.execute()
i += 20
sourceId.drop(20)
println("source Id:" + sourceId)
}
def createBatch(products: mutable.Map[String, List[String]]): ProductsCustomBatchRequest = {
val productsBatchRequestEntries = new util.ArrayList[ProductsCustomBatchRequestEntry]
products.map( i => productsBatchRequestEntries
.add(new ProductsCustomBatchRequestEntry()
.setBatchId(batchId.incrementAndGet())
.setProductId(i._1)
.set("brand", i._2(1))
.setMerchantId(merchantId)
.setMethod("insert")
))
println("batch Id " + batchId)
val batchRequest = new ProductsCustomBatchRequest
batchRequest.setEntries(productsBatchRequestEntries)
println("%%%%%%%%%%%%%%%%%%%%%%")
println(batchRequest)
batchRequest
}
}
}
Ошибка: исключение в потоке "main""," location ":" records "," locationType ":" other "," message ":" Неизвестное имя поля: бренд "," причина ":" неверно "}]," message ":" Неизвестное имя поля: бренд"} at com.google.api.client.googleapis.json.GoogleJsonResponseException.from (GoogleJsonResponseException.java:145) по адресу com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnQ3) .jpgна com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError (AbstractGoogleJsonClientRequest.java:40) на com.google.api.client.googleapis.services.AbstractGoogleClientRequestClient1. com.google.api.client.http.HttpRequest.execute (HttpRequest.java:1089) на com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed (AbstractGoogleClientRequest.java:419) по адресу com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed (AbstractGoogleClientRequest.java:352) в Google.google.Gl. AbstractGoogleClientRequest.java:469) по адресу com.ebctech.PAGFeed.ProductUpdtaeForParticularField $ .main (ProductUpdtaeForParticularField.scala: 38) по адресу com.ebctech.PAGFeed.ProductUpdtaeForParticularField.taF