c# - Google Merchant Product Feed not Accepting my Feed -
i working gdata api import products merchant feed. code follows:
list<productentry> newentries = new list<productentry>(); foreach (product prod in ent.products.where(i => !i.isdeleted && i.isdisplayed && i.price > 0)) { newentries.add(prod.getnewentry()); } string googleusername = "nope@gmail.com"; string googlepassword = "*****"; contentforshoppingservice service = new contentforshoppingservice("my store"); service.setusercredentials(googleusername, googlepassword); service.accountid = "*******"; service.showwarnings = true; productfeed pf = service.insertproducts(newentries); r.write(pf.entries.count.tostring());
this code returning me 1 entry, rather 400+ should, , 1 entry empty no error or warning info. nothing shows on merchant center dash. ideas on might occurring here?
or - how can more details on going on?
first of create service account on google developers console if don't have 1 already.
nuget package google.apis.shoppingcontent.v2
after whats mentioned on link you'll get
a clientid
a clientsecret
those using authenticate.
var credentials = googlewebauthorizationbroker.authorizeasync( new clientsecrets() { clientid = "yourclientid", clientsecret = "yourclientsecret" }, new string[] { shoppingcontentservice.scope.content }, "user", cancellationtoken.none).result; //make global variable or make sure pass insertproductbatch or function needs use service = new shoppingcontentservice(new baseclientservice.initializer() { httpclientinitializer = credentials, applicationname = "your-app-name" });
now insert part:
private async task<list<product>> insertproductbatch(ienumerable<product> products, ulong merchantaccountid) { // create batch request. batchrequest request = new batchrequest(service); list<product> responseproducts = new list<product>(); foreach (var p in products) { productsresource.insertrequest insertrequest = service.products.insert(p, merchantaccountid); request.queue<product>( insertrequest, (content, error, index, message) => { responseproducts.add(content); //responseproducts.add(content); if (content != null) { //product inserted } appendline(string.format("product inserted id {0}", ((product)content).id)); if (error != null) { //there error can access error message though error.message } }); } await request.executeasync(cancellationtoken.none); return responseproducts; }
and thats it.
Comments
Post a Comment