【问题标题】:sendText() & _sendDirectItem() & _prepareRecipients() must be of the type array, integer givensendText() & _sendDirectItem() & _prepareRecipients() 必须是数组类型,给定整数
【发布时间】:2023-03-31 11:09:02
【问题描述】:

我的日志中出现此错误:

ERROR - 2018-04-07 02:10:23 --> Severity: 4096 --> Argument 1 passed to InstagramAPI\Request\Direct::sendText() must be of the type array, integer given, called in /home/instapanel/public_html/app/helpers/instagram_helper.php on line 5968 and defined /home/instapanel/public_html/app/vendor/mgp25/instagram-php/src/Request/Direct.php 468
ERROR - 2018-04-07 02:10:23 --> Severity: 4096 --> Argument 2 passed to InstagramAPI\Request\Direct::_sendDirectItem() must be of the type array, integer given, called in /home/instapanel/public_html/app/vendor/mgp25/instagram-php/src/Request/Direct.php on line 489 and defined /home/instapanel/public_html/app/vendor/mgp25/instagram-php/src/Request/Direct.php 1002
ERROR - 2018-04-07 02:10:23 --> Severity: 4096 --> Argument 1 passed to InstagramAPI\Request\Direct::_prepareRecipients() must be of the type array, integer given, called in /home/instapanel/public_html/app/vendor/mgp25/instagram-php/src/Request/Direct.php on line 1132 and defined /home/instapanel/public_html/app/vendor/mgp25/instagram-php/src/Request/Direct.php 928

我认为它来自 instagram_helper.php 的代码:

if (!empty($users))
{
foreach($users as $user)
    {
    if (!empty($user))
        {
        $info = $i->people->getFriendship($user->id);
        if ($info->status == "ok")
            {
            $history = $CI->db->select("*")->where("pk", $user->username)->where("type", $data->category)->where("account_id", $data->account_id)->get(INSTAGRAM_HISTORY)->row();
            if (empty($history) && $info->following == "" && $info->outgoing_request == "" && $info->followed_by == 1)
                {
                $follow = $i->people->follow($user->id);

                // echo "<a href='https://instagram.com/".$user->username."' target='_blank'>".$user->username."</a>";

                if ($follow->status == "ok")
                    {
                    $messages = (array)json_decode($data->message);
                    $message_index = array_rand((array)json_decode($data->message));
                    if (!empty($messages))
                        {
                        $message = $spintax->process($messages[$message_index]);
                        if ($message != "")
                            {
                            $mess = $i->direct->sendText($user->id, $message);
                            }
                        }

                    $user->pk = $user->id;
                    $response = array(
                        "st" => "success",
                        "data" => json_encode($user) ,
                        "code" => $user->username,
                        "txt" => l('Successfully')
                    );
                    }

                break;
                }
            }
        }
    }
}

此代码来自 Instagram 名称 (EasyGram) 的自动引导脚本。在上次更新中,开发人员给了我新的 instagram_helper.php 文件,但它不适用于(自动定向到新的追随者)。有什么想法吗?

【问题讨论】:

    标签: php arrays instagram instagram-api


    【解决方案1】:

    替换:

    $mess = $i->direct->sendText($user->id, $message);
    

    $mess = $i->direct->sendText([$user->id], $message);
    

    看源码可以看到:

    /**
     * Send a direct text message to a user's inbox.
     *
     * @param array  $recipients An array with "users" or "thread" keys.
     *                           To start a new thread, provide "users" as an array
     *                           of numerical UserPK IDs. To use an existing thread
     *                           instead, provide "thread" with the thread ID.
     * @param string $text       Text message.
     * @param array  $options    An associative array of optional parameters, including:
     *                           "client_context" - predefined UUID used to prevent double-posting.
     *
     * @throws \InvalidArgumentException
     * @throws \InstagramAPI\Exception\InstagramException
     *
     * @return \InstagramAPI\Response\DirectSendItemResponse
     */
    
    public function sendText(
        array $recipients,
        $text,
        array $options = [])
    

    第一个参数 ($recipients) 必须是一个数组。

    【讨论】:

    • 感谢您的快速回复错误未显示,此问题已解决 但仍然 直接消息 根本不起作用:(
    猜你喜欢
    • 2017-09-20
    • 2017-05-06
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2016-06-05
    • 1970-01-01
    • 2022-08-23
    相关资源
    最近更新 更多