Ejemplo n.º 1
0
  public List<KeywordType> getAllKeyword(List<Long> adgroupIds) {
    if (logger.isDebugEnabled()) {
      logger.debug("推广单元总数: " + adgroupIds.size());
    }

    try {
      KeywordService keywordService = commonService.getService(KeywordService.class);

      List<KeywordType> keywordTypeList = new ArrayList<>();
      GetKeywordIdByAdgroupIdRequest kwIdRequest = new GetKeywordIdByAdgroupIdRequest();
      kwIdRequest.setAdgroupIds(adgroupIds);
      GetKeywordIdByAdgroupIdResponse response =
          keywordService.getKeywordIdByAdgroupId(kwIdRequest);
      if (response == null) {
        Thread.sleep(3000);
        response = keywordService.getKeywordIdByAdgroupId(kwIdRequest);
      }
      List<GroupKeywordId> groupKeywordIds = response.getGroupKeywordIds();
      List<Long> kwIds = new ArrayList<>(groupKeywordIds.size() << 1);

      for (GroupKeywordId gkId : groupKeywordIds) {
        kwIds.addAll(gkId.getKeywordIds());
      }

      GetKeywordByKeywordIdRequest getKeywordByKeywordIdRequest =
          new GetKeywordByKeywordIdRequest();
      getKeywordByKeywordIdRequest.setKeywordIds(kwIds);

      GetKeywordByKeywordIdResponse response1 =
          keywordService.getKeywordByKeywordId(getKeywordByKeywordIdRequest);
      if (response1 == null) {
        Thread.sleep(3000);
        response1 = keywordService.getKeywordByKeywordId(getKeywordByKeywordIdRequest);
      }

      if (logger.isDebugEnabled()) {
        logger.debug("当前请求得到的关键词总数: " + response1.getKeywordTypes().size());
      }

      keywordTypeList.addAll(response1.getKeywordTypes());

      if (keywordTypeList.size() == 0) {
        return Collections.emptyList();
      }

      return keywordTypeList;
    } catch (final Exception e) {
      e.printStackTrace();
    }

    return Collections.emptyList();
  }
Ejemplo n.º 2
0
  public List<KeywordType> setKeywordPrice(List<KeywordType> list) throws ApiException {
    if (list == null || list.size() == 0) {
      return Collections.emptyList();
    }

    UpdateKeywordRequest request = new UpdateKeywordRequest();
    request.setKeywordTypes(list);

    KeywordService keywordService = commonService.getService(KeywordService.class);
    UpdateKeywordResponse response = keywordService.updateKeyword(request);
    if (response == null) {
      return Collections.emptyList();
    }

    return response.getKeywordTypes();
  }
Ejemplo n.º 3
0
  public Integer deleteKeyword(List<Long> keywordIds) throws ApiException {
    DeleteKeywordRequest request = new DeleteKeywordRequest();
    request.setKeywordIds(keywordIds);

    KeywordService keywordService = commonService.getService(KeywordService.class);
    DeleteKeywordResponse response = keywordService.deleteKeyword(request);
    if (response == null) {
      try {
        TimeUnit.SECONDS.sleep(3);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      if (response != null) return response.getResult();
    }

    return -1;
  }
Ejemplo n.º 4
0
  public List<KeywordType> addKeyword(List<KeywordType> list) throws ApiException {
    AddKeywordRequest request = new AddKeywordRequest();
    request.setKeywordTypes(list);

    KeywordService keywordService = commonService.getService(KeywordService.class);
    AddKeywordResponse response = keywordService.addKeyword(request);
    if (response == null) {
      try {
        TimeUnit.SECONDS.sleep(3);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      if (response != null) return response.getKeywordTypes();
    }

    return Collections.emptyList();
  }
Ejemplo n.º 5
0
  public List<QualityType> getKeywordQuality(List<Long> keywordIds) {
    try {
      KeywordService keywordService = commonService.getService(KeywordService.class);
      GetKeywordQualityRequest request = new GetKeywordQualityRequest();
      request.setIds(keywordIds);
      request.setType(11); // 3: 表示指定id数组为计划id 5:表示指定id数组为单元id 11:表示指定id为关键词id

      GetKeywordQualityResponse response = keywordService.getKeywordQuality(request);

      if (response == null) {
        return Collections.emptyList();
      }
      return response.getQualities();
    } catch (ApiException e) {
      e.printStackTrace();
    }

    return Collections.emptyList();
  }