Advertisement
fauzanjeg

Test Twitter API

Jan 14th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. /* Test Twitter API */
  2. use Abraham\TwitterOAuth\TwitterOAuth;
  3. function test_twitter_api() {
  4.     $counter = 0;
  5.     if ( class_exists( 'Abraham\TwitterOAuth\TwitterOAuth' ) ) {
  6.         $tw_consumer_key = 'your_key'; /* Twitter Consumer Key */
  7.         $tw_consumer_secret = 'your_key'; /* Twitter Consumer Secret */
  8.         $tw_access_token = 'your_key'; /* Twitter Access Token */
  9.         $tw_access_token_secret = 'your_key'; /* Twitter Access Token Secret */
  10.  
  11.         $twitter_id = 'TwitterDev'; /* @TwitterDev || https://twitter.com/TwitterDev */
  12.  
  13.         $twitter  = new TwitterOAuth( $tw_consumer_key, $tw_consumer_secret, $tw_access_token, $tw_access_token_secret );
  14.         $userinfo = $twitter->get( 'users/lookup', array( 'screen_name' => $twitter_id ) );
  15.  
  16.         if ( empty( $userinfo ) || $userinfo->errors ) { /* If Error */
  17.             var_dump('Failed to Get data'); echo '<br>';
  18.             var_dump($userinfo); echo '<br>';
  19.             var_dump($userinfo->errors[0]->message); echo '<br>';
  20.         }else { /* If Success */
  21.             var_dump('Successfully Getting data'); echo '<br>';
  22.             var_dump($userinfo); echo '<br>';
  23.             $counter = (int) $userinfo[0]->followers_count;
  24.         }
  25.     }
  26.     var_dump($counter);
  27. }
  28.  
  29. add_action( 'jnews_after_body', 'test_twitter_api' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement