【问题标题】:How to deal with serialization - Campaign Monitor API如何处理序列化 - Campaign Monitor API
【发布时间】:2013-02-05 15:15:27
【问题描述】:

我正在使用 Campaign Monitor API 发送电子邮件。 API 允许通过名为 create_from_template() 的方法创建模板化电子邮件。作为the doc says,我需要添加一些格式化参数。以下是活动监视器 create_from_template() 方法实现的内容:

/**
     * Creates a new campaign from a template based on the info provided.
     * At least on of the ListIDs and Segments parameters must be provided
     * @param string $client_id The client to create the campaign for
     * @param array $campaign_info The campaign information to use during creation.
     *     This array should be of the form
     *     array(
     *         'Subject' => string required The campaign subject
     *         'Name' => string required The campaign name
     *         'FromName' => string required The From name for the campaign
     *         'FromEmail' => string required The From address for the campaign
     *         'ReplyTo' => string required The Reply-To address for the campaign
     *         'ListIDs' => array<string> optional An array of list ids to send the campaign to
     *         'SegmentIDs' => array<string> optional An array of segment ids to send the campaign to
     *         'TemplateID' => string required The ID of the template to use
     *         'TemplateContent' => array required The content which will be used to fill the editable areas of the template
     *     )
     * @access public
     * @return CS_REST_Wrapper_Result A successful response will be the ID of the newly created campaign
     */
    function create_from_template($client_id, $campaign_info)
    {
        return $this->post_request($this->_base_route . 'campaigns/' . $client_id . '/fromtemplate.json', $campaign_info);
    }

因此我给出了 $campaign_info 参数

        $list = array($list_id);
        $data = array(
            'Name' => $name_string,
            'Subject' => $subject_string,
            'FromName' => $some_name,
            'FromEmail' => "contact@email.org",
            'ReplyTo' => "contact@email.org",
            'ListIDs' => $list_id,
            'SegmentIDs' => array(),
            'TemplateID' => 'a6dd1168417a6d7d7f94da70c3cafe15'
            'TemplateContent' => array(
                                       'Singlelines' => array('Content' => $a_string ,
                                                              'Href' =>  $a_href
                                                              ),
                                        'Multilines' => array('Content' => $content
                                                             ),
                                        'Images' => array('Content' => $some_url,
                                                          'Href' => $some_href,
                                                         )

                                      )
                  );

但是当我向活动的监控服务器发起我的 api 发布请求时,我不断收到一条消息:

object(CS_REST_Wrapper_Result)#32 (2) { ["response"]=> object(stdClass)#29 (2) { ["Code"]=> int(400) ["Message"]=> string(110) "Failed to deserialize your request. Please check the documentation and try again. Fields in error: campaign" } ["http_status_code"]=> int(400) }

有人知道它来自哪里吗?

编辑:如果我传递这些参数

$template_content = array(
  'Singlelines' => array(),
  'Multilines' => array(),
  'Images' => array(),
  'Repeaters' => array()
);

然后在数组$data'TemplateContent' =&gt; $template_content中,一切正常,但是当我添加一些参数时,它就不起作用了

【问题讨论】:

  • 看来请求应该是json编码的。在将数组传递给 create_from_template 方法之前,您是否尝试过将数组包装在 json_encode() 中?
  • @ChrisHanson,看我的编辑,似乎可以理解数组格式
  • @ChrisHanson :事实上,我设法使用嵌套数组 => array(array('Content'=> $content,..)),

标签: php serialization http-post


【解决方案1】:

G'day user1611830,

根据sample in the github repo,单行、多行和图像中的每一个都需要是arrayarrays

最好为中继器添加一个空的array

所以你可能正在寻找这样的东西(如果我遗漏了任何括号,请道歉,但只要你将单行、多行和图像中的每一个包装在另一个 array() 中,你应该是对的:

$template_content = array(
    'Singlelines' => array(
        array(
            'Content' => $a_string,
            'Href' =>  $a_href
        )
    ),
    'Multilines' => array(
        array('Content' => $content)
     ),
    'Images' => array(
        array(
            'Content' => $some_url,
            'Href' => $some_href,
        )
    ),
    'Repeaters' => array()
);

【讨论】:

    猜你喜欢
    • 2014-05-02
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    相关资源
    最近更新 更多