我在将 klaviyo 与 laravel 集成时遇到了这个错误

编程入门 行业动态 更新时间:2024-10-15 12:34:23
本文介绍了我在将 klaviyo 与 laravel 集成时遇到了这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 这个包作为SDK.所以基本上我想要实现的是将用户添加到列表中,但具有同意状态或电子邮件和短信,我从我自己的问题的一个答案中找到的是这段代码.所以我尝试了一下,但后来又遇到了另一个错误.

I'm using this package As SDK. So basically what I'm trying to achieve is to add the users to a list but with the consent status or email and SMS, What I found from one answer from my own question is this code. So I tried it but then it hit another error.

TypeError
Cannot access offset of type string on string

来自@Ohgodwhy 的代码 答案.

Code from @Ohgodwhy's answer.

public function chnages()
    {
        $client = new Klaviyo('Your_Private_apikey', 'Public_Api_key');
        $customer_properties =  [
            '$email' => "someone@mailinator9",
            '$first_name' => "Thomas9",
            '$last_name' => "Jefferson",
            'phone_number' => "1234567890"
        ];
        $consents = [];
        if (request()->get('sms_consent', false)) {
            $consents['sms_consent'] = true;
        }
        if (request()->get('email_consent', false)) {
            $consents['email_consent'] = true;
        }
        foreach ($consents as $type => $consented) {
            if ($consented) {
                $consents['$consent'] = array_merge(
                    data_get($consents, '$consent', []),
                    [explode('_', $type)[0]] //e.g. sms, email
                );
            }
        }

        $client->lists->addSubscribersToList('LIST_ID', array_merge($customer_properties, $consents));
    }

推荐答案

$consents['$consent'] 这行不通,数组值可以是变量或字符串,但是不是字符串内的变量.此外,您的 foreach 中没有 $consent,要检查您需要执行的 $consents 键值 $consents[$type]对于 data_get($consents, '$consent', []) 来说同样重要,它需要 data_get($consents, $consents, [])

$consents['$consent'] this is not going to work, array values can be either a variable OR a string but not a variable inside a string. Also, you don’t have $consent in your foreach, to check the $consents key value you need to do $consents[$type] The same thing counts for data_get($consents, '$consent', []) which need to be data_get($consents, $consented, [])

这篇关于我在将 klaviyo 与 laravel 集成时遇到了这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 04:19:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/930449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   错误   klaviyo   laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!