|
@@ -224,10 +224,44 @@ class SBClient(BaseClient):
|
|
|
if not info.get("nextToken"):
|
|
|
break
|
|
|
body["nextToken"] = info["nextToken"]
|
|
|
- logger.info(f"总共数量:{info['totalResults']}")
|
|
|
+ # logger.info(f"总共数量:{info['totalResults']}")
|
|
|
|
|
|
- def get_ad_groups(self):
|
|
|
- pass
|
|
|
+ def get_ad_groups(self,**body):
|
|
|
+ url_path = "/sb/v4/adGroups/list"
|
|
|
+ headers = {
|
|
|
+ 'Content-Type': "application/vnd.sbadgroupresource.v4+json",
|
|
|
+ 'Accept': "application/vnd.sbadgroupresource.v4+json"
|
|
|
+ }
|
|
|
+ return self._request(url_path, method="POST", headers=headers,body=body)
|
|
|
+
|
|
|
+ def iter_adGroups(self, **body) -> Iterator[dict]:
|
|
|
+ if "maxResults" not in body:
|
|
|
+ body["maxResults"] = 100
|
|
|
+ while True:
|
|
|
+ info: dict = self.get_ad_groups(**body)
|
|
|
+ print(info)
|
|
|
+ yield from info["adGroups"]
|
|
|
+ if not info.get("nextToken"):
|
|
|
+ break
|
|
|
+ body["nextToken"] = info["nextToken"]
|
|
|
+
|
|
|
+ def get_ads(self,**body):
|
|
|
+ url_path = "/sb/v4/ads/list"
|
|
|
+ headers = {'Content-Type': "application/vnd.sbadresource.v4+json",
|
|
|
+ 'Accept': "application/vnd.sbadresource.v4+json"
|
|
|
+ }
|
|
|
+ return self._request(url_path, method="POST", headers=headers,body=body)
|
|
|
+
|
|
|
+ def iter_ads(self,**body):
|
|
|
+ if "maxResults" not in body:
|
|
|
+ body["maxResults"] = 100
|
|
|
+ while True:
|
|
|
+ info: dict = self.get_ads(**body)
|
|
|
+ print(info)
|
|
|
+ yield from info["ads"]
|
|
|
+ if not info.get("nextToken"):
|
|
|
+ break
|
|
|
+ body["nextToken"] = info["nextToken"]
|
|
|
|
|
|
def get_report(
|
|
|
self,
|
|
@@ -311,9 +345,10 @@ if __name__ == '__main__':
|
|
|
'lwa_client_secret': 'cbf0514186db4df91e04a8905f0a91b605eae4201254ced879d8bb90df4b474d',
|
|
|
'profile_id': "3006125408623189"
|
|
|
}
|
|
|
- sp = SPClient(**AWS_CREDENTIALS)
|
|
|
- print(sp.get_keyword_bidrecommendation(adGroupId="119753215871672",keyword=["8mp security camera system","8mp security camera system"],matchType=["broad","exact"]))
|
|
|
-
|
|
|
+ # sp = SPClient(**AWS_CREDENTIALS)
|
|
|
+ # print(sp.get_keyword_bidrecommendation(adGroupId="119753215871672",keyword=["8mp security camera system","8mp security camera system"],matchType=["broad","exact"]))
|
|
|
+ sb = SBClient(**AWS_CREDENTIALS)
|
|
|
+ print(list(sb.iter_ads()))
|
|
|
|
|
|
# sd = SDClient(**AWS_CREDENTIALS)
|
|
|
# print(sd.get_campaigns(startIndex=10, count=10))
|