I’ve recently been playing with the Twitter API using the Twitter::API module (in beta for v2 of the API) in Perl.

I’ve got get requests working, no problem. However, now I need to get posts working as well and it’s not entirely clear to me how to do this in the documentation at https://metacpan.org/pod/Twitter::API[sql](https://frontiertechnologyinstitute.com/sql-certification/)

best progress I’ve made so far is using the following:

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

This gets me ‘Requests with bodies must have content-type of application/json. at /usr/local/share/perl/5.30.0/Twitter/API.pm line 369’

I can see content_type is set in the client headers section:

'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'
                              },

I tried to add content-type in there as well with value ‘application/json’ but this made no difference.

If I remove the ‘tweet_id’ value then I get ‘The tweet_id field in the request body can not be empty at /usr/local/share/perl/5.30.0/Twitter/API.pm line 369’

The tweet_id is supposed to be set in the body of the request as per: Postman but I’m struggling to set this value correctly.

Grateful for insight and direction, thanks.

Thanks for reaching out here. You will have to pass tweet_id separately into the body of the request as a JSON object. Hope this helps!

Best,
Jessica

1 Like