· 7 years ago · Sep 05, 2018, 10:38 AM
1public function getApi() {
2 $r = Str::random(32);
3 $ch = curl_init();
4
5 $base = [
6 //'https://api.twitter.com/1.1/statuses/update.json',
7 //'include_entities' => 'true',
8 'oauth_consumer_key' => 'sTixaIOsTLzcwuAe0btnLCwWY',
9 'oauth_nonce' => $r,
10 'oauth_signature_method' => 'HMAC-SHA1',
11 'oauth_timestamp' => time(),
12 'oauth_token' => '3092554205-mRBgxFPCIJ8sh352vuc6FaebcebhBDDUj9M3XaW',
13 'oauth_version' => '1.0',
14 //'status' => 'Hello Ladies + Gentlemen, a signed OAuth request!'
15 ];
16 ksort($base);
17 $post_url = '';
18 foreach ($base AS $name => $value)
19 $post_url .= $name.'='.$value.'&';
20 $post_url = /*'POST&'.urlencode('https://api.twitter.com/1.1/statuses/update.json').'&'.*/urlencode(rtrim($post_url, '&'));
21
22 //echo $post_url;exit;
23
24 $sig_key = 'hvUEVKv8fnjSUSLAQ5M6IF6LZsGvlWxp1vu7tiL18iv9o5EkeW&KRluSPpHthbj6qddDdkW1iamOI3sXCfk0Z1V785HSXhcI';
25 $sha = hash_hmac('sha1', $post_url, $sig_key, true);
26 $sha = strtoupper($sha);
27 $output = str_split($sha,2);
28 $output = implode(' ',$output);
29 $output = base64_encode($output);
30
31
32 $header = [
33 'authorization: OAuth
34 oauth_consumer_key="sTixaIOsTLzcwuAe0btnLCwWY",
35 oauth_nonce="'.$r.'",
36 oauth_signature="'.$output.'",
37 oauth_signature_method="HMAC-SHA1",
38 oauth_timestamp="'.time().'",
39 oauth_token="3092554205-mRBgxFPCIJ8sh352vuc6FaebcebhBDDUj9M3XaW",
40 oauth_version="1.0"',
41 ];
42
43 curl_setopt($ch, CURLOPT_URL, "https://api.twitter.com/1.1/users/show.json?screen_name=twitterdev");
44 curl_setopt($ch, CURLOPT_POST, 0);
45 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
46 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
47
48 $server_output = curl_exec ($ch);
49
50 curl_close ($ch);
51
52 print_r(json_decode($server_output));
53 }