Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在node.js中使用更新的Twitter API;事件:字段为必填项“;_Node.js_Api_Npm_Twitter - Fatal编程技术网

如何在node.js中使用更新的Twitter API;事件:字段为必填项“;

如何在node.js中使用更新的Twitter API;事件:字段为必填项“;,node.js,api,npm,twitter,Node.js,Api,Npm,Twitter,在尝试使用Twitter API发送直接消息时,我不断遇到以下错误 message: 'event: field is required', code: 214, allErrors: [ { code: 214, message: 'event: field is required' } ], twitterReply: { errors: [ [Object] ] }, statusCode: 400 } { errors: [ { code: 214, message: '

在尝试使用Twitter API发送直接消息时,我不断遇到以下错误

message: 'event: field is required',
  code: 214,
  allErrors: [ { code: 214, message: 'event: field is required' } ],
  twitterReply: { errors: [ [Object] ] },
  statusCode: 400 }
{ errors: [ { code: 214, message: 'event: field is required' } ] }
Twitter最近更新了他们的api(im告知),因此现在使用“direct_messages/events/new”url发送直接消息。我正在使用“twit”模块访问api

export async function messageTwitter(message, recipient){
    client.post('direct_messages/events/new',{
        screen_name: recipient,
        text: message
    }, (event, error)=>{
            console.log(event)
            console.log(error)
    })
}

我希望post请求的格式正确,但在说明如何定义“事件”的文档中找不到任何信息。

在根据我得到的错误胡乱处理之后,我找到了如何格式化对象的方法。对不起,我知道这是一个愚蠢的、问得不好的问题。这是我的更新代码:

export async function messageTwitter(message, recipient){
    client.post('direct_messages/events/new', {
        event: {
            type: "message_create",
            message_create: {
                target: {
                    recipient_id: recipient
                },
                message_data: {
                    text: message
                }
            }
        }
    }, (error, event)=>{
            if(error){
              console.log(error)
            }
            else{
               console.log(event);
             }
    })
}

直接消息上的Twitter API文档在这里没有帮助吗?是的,但我不知道“事件”字段是什么意思,我也找不到任何更新的帖子来处理更新后的API。