Google 商家产品 Feed 不接受我的 Feed
Google Merchant Product Feed not Accepting my Feed
我正在使用 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());
此代码向我返回了 1 个条目,而不是它应该返回的 400 多个条目,并且那 1 个条目是空的,没有错误或警告信息。我的 Merchant Center 仪表板上没有显示任何内容。关于这里可能发生的事情有什么想法吗?
或者 - 我怎样才能获得有关正在发生的事情的更多详细信息?
首先 create a service account 关于 Google 开发者
控制台,如果你还没有。
完成 link 中提到的内容后,您将获得
一个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;
}
仅此而已。
我正在使用 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());
此代码向我返回了 1 个条目,而不是它应该返回的 400 多个条目,并且那 1 个条目是空的,没有错误或警告信息。我的 Merchant Center 仪表板上没有显示任何内容。关于这里可能发生的事情有什么想法吗?
或者 - 我怎样才能获得有关正在发生的事情的更多详细信息?
首先 create a service account 关于 Google 开发者 控制台,如果你还没有。
完成 link 中提到的内容后,您将获得
一个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;
}
仅此而已。