|
@@ -15,7 +15,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 头条-视频素材
|
|
@@ -81,4 +83,77 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
getFileVideoData(oauthToken,startDate, endDate,page, 100);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 根据账户获取视频素材-账户下全部视频素材
|
|
|
+ *
|
|
|
+ * @param oauthToken
|
|
|
+ * @param page
|
|
|
+ * @param pageSize
|
|
|
+ * @return: java.util.Map<java.lang.String,java.lang.String>
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/9
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String,String> getBytedanceVideoByAccountId(OauthToken oauthToken,int page, int pageSize) {
|
|
|
+ Map<String,String> resultMap = new HashMap<>();
|
|
|
+ log.info("调用接口------getBytedanceVideoByAccountId----根据账户获取视频素材---账户--{}===第{}页===》》》",oauthToken.getAccountId(),page);
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_FILE_VIDEO_GET;
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", oauthToken.getAccountId());
|
|
|
+ param.put("page", page);
|
|
|
+ param.put("page_size", pageSize);
|
|
|
+ /*
|
|
|
+ JSONObject param2 = new JSONObject();
|
|
|
+ if (!Check.isNull(startDate)){
|
|
|
+ param2.put("start_time",startDate);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(endDate)){
|
|
|
+ param2.put("end_time",endDate);
|
|
|
+ }
|
|
|
+ param.put("filtering",param2);
|
|
|
+ */
|
|
|
+ JSONObject resultObject = HttpUtils.bytedanceGetRequest(oauthToken.getAccessToken(), url, param);
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
+ if (null == code || !code.equals(0)) {
|
|
|
+ log.error("获取视频素材接口异常==》accountId:{},message:{}", oauthToken.getAccountId(), resultObject.getString("message"));
|
|
|
+ resultMap.put("code","1");
|
|
|
+ resultMap.put("message","获取视频素材接口异常!账户:"+oauthToken.getAccountId()+"-----error:"+resultObject.getString("message"));
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (null == data || data.isEmpty()) {
|
|
|
+ resultMap.put("code","0");
|
|
|
+ resultMap.put("message","获取视频素材数据为空");
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ List<BytedanceFileVideoGet> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject dataObject = data.getJSONObject(i);
|
|
|
+ try {
|
|
|
+ BytedanceFileVideoGet report = JSONObject.parseObject(dataObject.toJSONString(), BytedanceFileVideoGet.class);
|
|
|
+ report.setAdvertiserId(oauthToken.getAccountId());
|
|
|
+ report.setVideoUrl("https://aweme.snssdk.com/aweme/v1/playwm/?video_id=" + report.getId() + "&line=0");
|
|
|
+ list.add(report);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("错误:{}", e.toString());
|
|
|
+ resultMap.put("code","500");
|
|
|
+ resultMap.put("message","哎呀,网络不给力。"+e.toString());
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bytedanceFileVideoGetMapper.insert(list);
|
|
|
+ page++;
|
|
|
+ int totalPage = resultObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getBytedanceVideoByAccountId(oauthToken,page, 100);
|
|
|
+ }
|
|
|
+ resultMap.put("code","0");
|
|
|
+ resultMap.put("message","success");
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|