使用createsend&Python调用活动监视器获取订户

2024-05-13 10:34:34 发布

您现在位置:Python中文网/ 问答频道 /正文

阿罗哈朋友们

很抱歉这个愚蠢的问题,我还处于Python和编程的初级阶段,我正试图找到一种更好的方法来完成非常手工的任务。在

我想得到所有的订户从活动监视器使用它的API

我反复阅读了API文档,得出了需要使用以下代码片段的结论:

 from __future__ import absolute_import

import json

from createsend.createsend import CreateSendBase, BadRequest
from createsend.utils import json_to_py, validate_consent_to_track


class Subscriber(CreateSendBase):
    """Represents a subscriber and associated functionality."""

    def __init__(self, auth=None, list_id=None, email_address=None):
        self.list_id = list_id
        self.email_address = email_address
        super(Subscriber, self).__init__(auth)

    def get(self, list_id=None, email_address=None, include_tracking_preference=False):
        """Gets a subscriber by list ID and email address."""
        params = {
            "email": email_address or self.email_address,
            "includetrackingpreference": include_tracking_preference,
        }
        response = self._get("/subscribers/%s.json" %
                             (list_id or self.list_id), params=params)
        return json_to_py(response)

我对代码有点迷茫,我不确定是否需要用API键结束上面的create send类,上面的代码是否会给我一个完整的Json订户列表。。?在

我现在正在Udemy上学习一门基本的API课程,所以我知道如何使用postman和使用Flask运行基本API调用,但是我没有见过或使用Createsend。在

代码here的Github

文档here

对于任何读到这篇文章的人,我真的很感谢你的时间,(不管你是否回复)!在

此致:, 数据新手。在


Tags: to代码fromimportselfnoneapiid
1条回答
网友
1楼 · 发布于 2024-05-13 10:34:34

来自另一个新手的问候。昨天在我试图使用他们的API向列表添加订阅者时看到了你的帖子。我有点挣扎,只能在高级开发人员的帮助下解决问题,所以不要自责。我知道可能有点晚了,但希望还是有帮助。如果你同时解决了这个问题,请告诉我:-)

首先,如果你想让一个列表的所有订阅者,你需要看这个部分https://www.campaignmonitor.com/api/lists/上面的内容一次可能会给你一个订阅者。我建议使用Postman这样的工具对API进行一些test-GET调用,看看哪一个可以得到所需的结果。例如,当我对一个列表的所有活动订阅者进行get调用时,我得到的结果是:

{
    "Results": [
        {
            "EmailAddress": "marco@polo.bro",
            "Name": "Marco",
            "Date": "2018-11-13 10:36:00",
            "State": "Active",
            "CustomFields": [],
            "ReadsEmailWith": ""
        },
        {
            "EmailAddress": "marco@polo.broke",
            "Name": "Marco",
            "Date": "2018-11-13 10:38:00",
            "State": "Active",
            "CustomFields": [],
            "ReadsEmailWith": ""
        },
        {
            "EmailAddress": "marco@polo.mkd",
            "Name": "Marco",
            "Date": "2018-11-13 17:22:00",
            "State": "Active",
            "CustomFields": [],
            "ReadsEmailWith": ""
        },
        {
            "EmailAddress": "marco@polo.ro",
            "Name": "Marco",
            "Date": "2018-11-13 09:52:00",
            "State": "Active",
            "CustomFields": [],
            "ReadsEmailWith": ""
        },
        {
            "EmailAddress": "subscriber1@example.com",
            "Name": "New Subscriber",
            "Date": "2018-11-13 16:55:00",
            "State": "Active",
            "CustomFields": [],
            "ReadsEmailWith": ""
        },
        {
            "EmailAddress": "subscriber2@example.com",
            "Name": "New Subscriber 2",
            "Date": "2018-11-13 16:59:00",
            "State": "Active",
            "CustomFields": [],
            "ReadsEmailWith": ""
        }
    ],
    "ResultsOrderedBy": "email",
    "OrderDirection": "asc",
    "PageNumber": 1,
    "PageSize": 1000,
    "RecordsOnThisPage": 6,
    "TotalNumberOfRecords": 6,
    "NumberOfPages": 1
}

否则,请尝试以下操作(应创建订阅服务器类的实例):

^{pr2}$

我想你也可以不用任何参数就可以得到细节。在

希望有帮助。在

快乐编码:-)

相关问题 更多 >