1

I am using Twitter API https://github.com/abraham/twitteroauth for getting tweets from the Twitter, I basically need to get non_public_metrics from the Twitter. I am successfully able to get the public_metrics but not non_public_metrics. Here is my request code:

$connection = new TwitterOAuth('', '', '', '');
$connection->setApiVersion('2');
$response = $connection->get('users/:id/tweets', [ 'tweet.fields' => 'non_public_metrics']);
echo 'response:<pre>';print_r($response);die;

I am getting following in response:

stdClass Object
(
    [meta] => stdClass Object
    (
        [result_count] => 0
        [next_token] => 1234567891234567891235jhgg12345
    )

)

I printed my request as well and it looks like this:

Abraham\TwitterOAuth\Request Object
(
    [parameters:protected] => Array
    (
        [oauth_version] => 1.0
        [oauth_nonce] => 6a232bfaef645a4791669cfc720bff75
        [oauth_timestamp] => 1668067530
        [oauth_consumer_key] => ---HERE CONSUMER KEY --
        [oauth_token] => ---HERE TOKEN PRINTS --
        [tweet.fields] => non_public_metrics
    )

    [httpMethod:protected] => GET
    [httpUrl:protected] => https://api.twitter.com/2/users/:id/tweets
    [json:protected] => 
)

Please help me in knowing why I am not getting [data] in case of this request, and if I use request for public_metrics then I get full result:

Request:
$connection = new TwitterOAuth('', '', '', '');
$connection->setApiVersion('2');

$response = $connection->get('users/:id/tweets', [ 'tweet.fields' => 'public_metrics']);
echo 'response==<pre>';print_r($response);die;

Response:
stdClass Object
(
    [data] => Array
    (
        [0] => stdClass Object
            (
                [id] => 416515058510215112
                [public_metrics] => stdClass Object
                    (
                        [retweet_count] => 0
                        [reply_count] => 0
                        [like_count] => 1
                        [quote_count] => 0
                    )

                [text] => @test He's right about 2020.
                [edit_history_tweet_ids] => Array
                    (
                        [0] => 12345678774514515
                    )

            )

        [1] => stdClass Object
            (
                [id] => 54687893265156122315465
                [public_metrics] => stdClass Object
                    (
                        [retweet_count] => 0
                        [reply_count] => 0
                        [like_count] => 0
                        [quote_count] => 0
                    )

                [text] => how do I interpret these daily projection numbers
                [edit_history_tweet_ids] => Array
                    (
                        [0] => 2315646415465464
                    )

            )

    )

    [meta] => stdClass Object
    (
        [result_count] => 10
        [newest_id] => 1515445121211654654
        [oldest_id] => 1514894156149845151
        [next_token] => 151515151515151fd5fgdf5g5151fd5gr4er
    )

)

Thanks!

user1578460
  • 315
  • 1
  • 2
  • 17

1 Answers1

1

I am able to understand why I am getting empty data, its because the tweets of the account which I was trying to fetch were 3 months old. When I posted latest tweet then I started getting data. And it is because Twitter documentation says:

Non-public, organic, and promoted metrics are only available for Tweets that have been created within the last 30 days.

Thanks!

user1578460
  • 315
  • 1
  • 2
  • 17