doukai2839 2018-09-24 21:48
浏览 102

PHP Twitter api具有事件类型的新直接消息(更改为2018年9月)

Use the twitter API to send direct messages, with the following method: "POST direct_messages / new" with php, tmhOAuth library.

Since a few days ago they changed (as indicated in migration documentation ) by the method: "POST direct_messages / events / new", where the structure of the post parameters changes, which are json.

Making the changes that indicate, when testing get response code 415: "Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings" (twitter help)

Adding a url callback to the app, keeps giving the same error. Did someone have the same problem when they migrated? any suggestions?

I detail the changes implemented, with some code:

    $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) In "options" the format is changed, by the requested json,

2) "json_encode" function is used before sending in request method.

3) Headers "Content-Type" are added to be taken by the tmhOAuth library.

Thanks for any comments or help

  • 写回答

1条回答 默认 最新

  • dpv21589 2019-03-07 16:56
    关注

    tmhOauth is too old and hasn't been updated for a while. I lost some time trying to adjust it and finally switched to https://twitteroauth.com/

    I was able to send DM in 1 min and 4 lines of codes just following their example in section JSON data.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝