Advertisement
Kocenggg

Get Tweet

Mar 9th, 2023 (edited)
869
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2.  
  3. function guestToken() {
  4.     $ch = curl_init();
  5.     curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/1.1/guest/activate.json');
  6.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7.     curl_setopt($ch, CURLOPT_POST, 1);
  8.     curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  9.     $headers = array();
  10.     $headers[] = 'Authorization: Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA';
  11.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  12.     $result = curl_exec($ch);
  13.     if (curl_errno($ch)) {
  14.         echo 'Error:' . curl_error($ch);
  15.     }
  16.     curl_close($ch);
  17.     return $result;
  18. }
  19.  
  20. function getTwitter($token, $tid){
  21.     $ch = curl_init();
  22.     curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/2/timeline/conversation/'.$tid.'.json?cards_platform=Web-12&include_cards=1');
  23.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  24.     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  25.     curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  26.     $headers = array();
  27.     $headers[] = 'X-Guest-Token: '.$token;
  28.     $headers[] = 'Authorization: Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA';
  29.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  30.     $result = curl_exec($ch);
  31.     if (curl_errno($ch)) {
  32.         echo 'Error:' . curl_error($ch);
  33.     }
  34.     curl_close($ch);
  35.     return $result;
  36. }
  37.  
  38. $guest = @json_decode(guestToken());
  39.  
  40. if($guest->guest_token){
  41.     $tid = $_GET['tid'];
  42.     $twitter = getTwitter($guest->guest_token, $tid);
  43.     header("Access-Control-Allow-Origin: *");
  44.     header("Access-Control-Allow-Headers: *");
  45.     header('Content-Type: application/json');
  46.     echo $twitter;
  47. }
  48.  
  49. ?>
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement