1

阿罗哈朋友们,

为这个愚蠢的问题道歉,我对 Python 和编程还处于起步阶段,我正在努力寻找一种更好的方法来完成一项非常非常手动的任务。

我想使用它的 API 从 Campaign Monitor 获取所有订阅者

我已经阅读并重新阅读了 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 密钥在其上方附加创建发送类,并且上面是否会给我一个完整的 Json 订阅者列表..?

我目前正在 Udemy 上学习基本的 API 课程,所以我知道如何使用邮递员并使用 Flask 运行基本的 api 调用,但我没有见过或使用过 Createsend。

代码的 Github 在这里

文档在这里

对于阅读本文的任何人,我非​​常感谢您的时间,(无论您是否回复)!

此致,Datanovice。

4

1 回答 1

2

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

首先,如果你想让所有订阅者都加入一个列表,你需要查看这部分https://www.campaignmonitor.com/api/lists/上面可能会一次给你一个订阅者。我建议使用 Postman 之类的工具对 API 进行一些测试 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
}

否则,试试这个(你应该创建一个订阅者类的实例):

from createsend import * 

list_id = 'your-list-id'
subscriber = Subscriber(
    {'api_key': 'your-api-key'},
    list_id,
    email_address=None
)

user_email = 'user@example.com'
subscriber.get(list_id, user_email, include_tracking_preference=True|False)

我认为您也可以直接subscriber.get()获取详细信息而无需任何争论。

希望能帮助到你。

快乐编码:-)

于 2018-11-14T10:02:48.493 回答