【问题标题】:PHP Twitter api New direct messages with event type (change september 2018)PHP Twitter api 带有事件类型的新直接消息(2018 年 9 月更改)
【发布时间】:2019-02-28 11:12:26
【问题描述】:

使用 twitter API 发送直接消息,使用以下方法:“POST direct_messages / new”与 php、tmhOAuth 库。

从几天前开始,它们发生了变化(如migration documentation 所示 ) 方法:"POST direct_messages/events/new",这里post参数的结构发生变化,都是json。

进行更改表明,在测试时获取响应代码 415:“回调 URL 未获批准用于此客户端应用程序。批准的回调 URL 可以在您的应用程序设置中调整”(twitter help)

向应用程序添加 url 回调,不断给出相同的错误。有人在迁移时遇到同样的问题吗?有什么建议吗?

我用一些代码详细说明了实现的变化:

    $options = array(
    "event"                 => array(
                                    "type"              => 'message_create',
                                    "message_create"    => array(
                                    "target"        => array('recipient_id'     => $id_usuario),    
                                                                                "message_data"  => array('text'             => $texto),
                                                    ),
                    )
            );
    $json_options = json_encode($options);
    $headers_extra = array('Content-Type' => 'application/json');

    $code = $this->_tmhOAuth->request('POST', $this->_tmhOAuth->url('1.1/direct_messages/events/new'), $json_options, $headers_extra);

1) 在“选项”中,格式被请求的 json 更改,

2) 在请求方法中发送前使用“json_encode”函数。

3) 添加标题“Content-Type”以供 tmhOAuth 库使用。

感谢任何 cmets 或帮助

【问题讨论】:

    标签: php json api twitter


    【解决方案1】:

    tmhOauth 太旧,有一段时间没有更新了。我花了一些时间尝试调整它,最后切换到https://twitteroauth.com/

    按照 JSON 数据 部分中的示例,我能够在 1 分钟和 4 行代码内发送 DM。

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多