我只需要提取字符串中的特定元素值。下面是我使用 Facebook AdsInsight API 获取 AdsInsight 数据的代码。
class LibFacebook:
def __init__(self, app_id, app_secret, access_token, ad_account_id):
FacebookAdsApi.init(app_id, app_secret, access_token)
self.account = AdAccount(ad_account_id)
#get ads insight
insights = self.account.get_insights(fields=[
AdsInsights.Field.campaign_id,
AdsInsights.Field.actions,
], params={
'level': AdsInsights.Level.campaign,
})
print(insights)
输出
<AdsInsights> {
"campaign_id": "23843294609751234",
"actions": [
{
"action_type": "post_reaction",
"value": "1"
},
{
"action_type": "landing_page_view",
"value": "78"
},
{
"action_type": "link_click",
"value": "163"
}
]
问题:与campaign_id 值(23843294609751234)一起,我只需要landing_page_view的值,即78(而不是其他操作项)并将其放入df 中。我如何访问它们?
更多信息:AdsInsights.Field.actions 是字符串类型。
type(AdsInsights.Field.actions)
str