添加抖音分类id获取方式
This commit is contained in:
@@ -571,6 +571,60 @@ func (a *API) GetProductAuditList(page, pageSize, status int64) ([]product_audit
|
||||
return result.Data.Records, result.Data.Total, nil
|
||||
}
|
||||
|
||||
// GetRecommendCategoryByName 根据名称预测商品类目,优先四级>三级>二级>1级
|
||||
func (a *API) GetRecommendCategoryByName(name string) (int64, error) {
|
||||
if name == "" {
|
||||
return 0, errors.New("抖音根据名称预测分类,名称不能为空")
|
||||
}
|
||||
request := product_GetRecommendCategory_request.New()
|
||||
request.Param.Scene = "category_infer"
|
||||
request.Param.Name = name
|
||||
|
||||
result, err := request.Execute(a.accessTokenObj)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if result.Code != RequestSuccessCode {
|
||||
return 0, errors.New(result.SubMsg + ":" + result.LogId)
|
||||
}
|
||||
|
||||
if len(result.Data.CategoryDetails) == 0 {
|
||||
return 0, errors.New("抖音根据图片获取分类,返回值为0")
|
||||
}
|
||||
|
||||
var firstCid int64
|
||||
var secondCid int64
|
||||
var thirdCid int64
|
||||
var fourthCid int64
|
||||
|
||||
index := len(result.Data.CategoryDetails) - 1
|
||||
if result.Data.CategoryDetails[index].CategoryDetail.FirstCid != 0 {
|
||||
firstCid = result.Data.CategoryDetails[index].CategoryDetail.FirstCid
|
||||
}
|
||||
if result.Data.CategoryDetails[index].CategoryDetail.SecondCid != 0 {
|
||||
secondCid = result.Data.CategoryDetails[index].CategoryDetail.SecondCid
|
||||
}
|
||||
if result.Data.CategoryDetails[index].CategoryDetail.ThirdCid != 0 {
|
||||
thirdCid = result.Data.CategoryDetails[index].CategoryDetail.ThirdCid
|
||||
}
|
||||
if result.Data.CategoryDetails[index].CategoryDetail.FourthCid != 0 {
|
||||
fourthCid = result.Data.CategoryDetails[index].CategoryDetail.FourthCid
|
||||
}
|
||||
if fourthCid != 0 {
|
||||
return fourthCid, nil
|
||||
}
|
||||
if thirdCid != 0 {
|
||||
return thirdCid, nil
|
||||
}
|
||||
if secondCid != 0 {
|
||||
return secondCid, nil
|
||||
}
|
||||
if firstCid != 0 {
|
||||
return firstCid, nil
|
||||
}
|
||||
return 0, errors.New("抖音获取推荐分类异常")
|
||||
}
|
||||
|
||||
// GetRecommendCategory 根据图片预测商品类目,优先四级>三级>二级>1级
|
||||
func (a *API) GetRecommendCategory(picParams []string) (int64, error) {
|
||||
if len(picParams) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user