Google Merchant Feed Feed未接受我的Feed

时间:2015-04-02 14:13:58

标签: c# gdata google-shopping-api

我正在使用GData api将产品导入我的商家Feed。代码如下:

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());

此代码返回给我一个条目,而不是它应该的400+,并且该条目为空,没有错误或警告信息。我的商家中心仪表板上没有显示任何内容。关于这里可能发生什么的任何想法?

或者 - 我怎样才能获得有关正在发生的事情的更多细节?

1 个答案:

答案 0 :(得分:2)

在您完成链接上提到的内容后,您将获得

  • 一个ClientId

  • ClientSecret

我们将用于验证的那些。

 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"
        });

现在为插入部分:

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;
        }

这就是全部。