Facebook 营销 API 代码无法在计算引擎上正常运行



我正试图在我的计算引擎上运行一些python代码,以便每天从facebook营销api中提取报告。

我目前已经设置了api来提取广告账户的所有广告id,它们以facebook的奇怪格式出现:

[<Ad> {
"id": "23845614332840309"
}, <Ad> {
"id": "23845614435580309"
}, <Ad> {
"id": "23845614435590309"
},
...

因此,我试图在没有其他格式化的情况下获得id列表,并且我使用以下代码:

test2 = [i for i in facebook_ad_ids]
test4 = []
for i in range(len(test2)):
test4.append(str(test2[i]))
in2 = []
for i in range(len(test4)):
in2.append(int(re.findall(r'bd+b', test4[i])[0]))

这个代码在我自己的电脑上运行得很好,但当我上传到计算引擎时,我会收到错误:

File "upload_test.py", line 30, in <listcomp>
test2 = [i for i in facebook_campaign_ids]
File "/home/name/.local/lib/python3.8/site-packages/facebook_business/api.py", line 783, in __next__
if not self._queue and not self.load_next_page():
File "/home/name/.local/lib/python3.8/site-packages/facebook_business/api.py", line 833, in load_next_page
self.params['summary'] = True
TypeError: list indices must be integers or slices, not str

通过在我的计算引擎上从Ubuntu 20.04切换到Debian/Linux 9解决了我的问题

最新更新