[英]Google Merchant Product Feed not Accepting my Feed
I am working with the GData api to import products to my merchant feed. 我正在使用GData API将产品导入到我的商家Feed中。 The code is as 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 is returning to me 1 entry, rather than the 400+ it should, and that 1 entry is empty with no error or warning info. 此代码返回给我1个条目,而不是应返回的400+,并且该1个条目为空,没有错误或警告信息。 Nothing shows on my merchant center dash.
我的商人中心破折号上没有任何显示。 Any ideas on what might be occurring here?
关于这里可能发生什么的任何想法?
OR - how can I get more details on what is going on? 或-我如何获得正在发生的事情的更多详细信息?
First of all create a service account on Google Developers Console if you don't have one already. 首先,如果您还没有帐户,请在Google Developers Console上创建一个服务帐户 。
NuGet package Google.Apis.ShoppingContent.v2 NuGet包Google.Apis.ShoppingContent.v2
after you do whats mentioned on the link you'll get 完成链接上提到的操作后,您将获得
a ClientId 客户编号
a ClientSecret 客户秘密
those we will be using to authenticate. 我们将用于认证的那些。
var credentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets() {
ClientId = "yourclientid",
ClientSecret = "yourclientsecret" },
new string[] { ShoppingContentService.Scope.Content },
"user",
CancellationToken.None).Result;
//make this a global variable or just make sure you pass it to InsertProductBatch or any function that needs to use it
service = new ShoppingContentService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials,
ApplicationName = "Your-app-name"
});
Now for the insert part: 现在是插入部分:
private async Task<List<Product>> InsertProductBatch(IEnumerable<Product> products, ulong merchantaccountid)
{
// Create a 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 successfully
}
AppendLine(String.Format("Product inserted with id {0}", ((Product)content).Id));
if (error != null)
{
//there is an error you can access the error message though error.Message
}
});
}
await request.ExecuteAsync(CancellationToken.None);
return responseproducts;
}
And thats all to it. 仅此而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.