J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 802 forks source link

engagement endpoint #288

Open ghadayoussef opened 4 years ago

ghadayoussef commented 4 years ago

I'm trying to hit the engagement endpoint but it always return status code :400 ,does anyone understand why ? function getEngagement($token,$tokenSecret){ $settings = array( 'oauth_access_token' => $token, 'oauth_access_token_secret' => $tokenSecret, 'consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET') );

    //$url = 'https://data-api.twitter.com/insights/engagement/totals';
    $url = 'https://data-api.twitter.com/insights/engagement/28hr';
    $requestMethod = 'POST';
   $postfields = array(
        'tweet_ids'=>array('1217776265337475073',
          '1217183078503845893'),
          'engagement_types'=> array(
            'impressions',
           ' engagements',
           ' url_clicks',
            'detail_expands'
          ),
        'groupings'=> array(
            'grouping name'=> array(
            'group_by'=>array(
              "tweet.id",
              "engagement.type",
              "engagement.hour"
            )))

        );

    $engagement = new TwitterAPIExchange($settings);
    $engagement->buildOauth($url, $requestMethod)->performRequest(true, [
                CURLOPT_HTTPHEADER => array('Content-Type:application/json','Accept-Encoding:gzip'),
                CURLOPT_POSTFIELDS => json_encode($postfields)
                ]);
    dd($engagement);

}