perl 向users/:id/retweets端点提交成功的POST请求

dluptydi  于 10个月前  发布在  Perl
关注(0)|答案(1)|浏览(100)

我最近一直在使用Perl中的Twitter::API模块(API v2的beta版)来使用Twitter API。
我已经收到请求了,没问题。然而,现在我需要让帖子也能正常工作,我不完全清楚如何在https://metacpan.org/pod/Twitter::API的文档中做到这一点。
到目前为止,我取得的最大进步是使用以下内容:

$client->post
        (
            'users/:id/retweets',
            {
                id => $userId,
                tweet_id => $id,
            },
        );

字符串
这让我得到'带有body的请求必须具有application/json的content-type。地址:/usr/local/share/perl/5.30.0/Twitter/API.pm第369行
我可以看到content_type在客户端头部分设置:

'headers' => {
                                'content_type' => 'application/json;charset=utf8',
                                'accept' => 'application/json',
                                'user_agent' => 'Twitter-API/1.0006 (Perl)',
                                'x_twitter_client' => 'Twitter-API/1.0006 (Perl)',
                                'x_twitter_client_url' => 'https://github.com/semifor/Twitter-API',
                                'x_twitter_client_version' => '1.0006'
                              },


我尝试在其中添加content-type以及值'application/json',但这没有任何区别。
如果我删除tweet_id值,那么我会得到:
在/usr/local/share/perl/5.30.0/Twitter/API.pm第369行,请求正文中的tweet_id字段不能为空。
tweet_id应该在请求的主体中设置为:https://www.postman.com/twitter/workspace/twitter-s-public-workspace/request/9956214-3ae30a68-4f8b-430e-8e46-cc5eeb44818d但是我很难正确设置这个值。
感谢您的洞察力和指导。

bksxznpy

bksxznpy1#

我知道这个答案来得很晚,但希望它对某人有用:
在我看来,-to_json选项是必要的,所以,一些沿线:

$client->post(
  'users/:id/retweets',
  {
    -to_json => { 
      id => $userId,
      tweet_id => $id,
    }
  }
);

字符串

相关问题