· 5 years ago · Dec 12, 2019, 10:28 AM
1<?php
2 function buildBaseString($baseURI, $method, $params) {
3 $r = array();
4 ksort($params);
5 foreach($params as $key=>$value){
6 $r[] = "$key=" . rawurlencode($value);
7 }
8 return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
9 }
10
11 function buildAuthorizationHeader($oauth) {
12 $r = 'Authorization: OAuth ';
13 $values = array();
14 foreach($oauth as $key=>$value)
15 $values[] = "$key=\"" . rawurlencode($value) . "\"";
16 $r .= implode(', ', $values);
17 return $r;
18 }
19
20 $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
21
22 $oauth_access_token = "xxx";
23 $oauth_access_token_secret = "vvvvv";
24 $consumer_key = "xxxxx";
25 $consumer_secret = "nnnnnn";
26
27 $oauth = array( 'oauth_consumer_key' => $consumer_key,
28 'oauth_nonce' => time(),
29 'oauth_signature_method' => 'HMAC-SHA1',
30 'oauth_token' => $oauth_access_token,
31 'oauth_timestamp' => time(),
32 'oauth_version' => '1.0');
33
34 $base_info = buildBaseString($url, 'GET', $oauth);
35 $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
36 $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
37 $oauth['oauth_signature'] = $oauth_signature;
38
39 $header = array(buildAuthorizationHeader($oauth), 'Expect:');
40 $options = array( CURLOPT_HTTPHEADER => $header,
41 //CURLOPT_POSTFIELDS => $postfields,
42 CURLOPT_HEADER => false,
43 CURLOPT_URL => $url,
44 CURLOPT_RETURNTRANSFER => true,
45 CURLOPT_SSL_VERIFYPEER => false);
46
47 $feed = curl_init();
48 curl_setopt_array($feed, $options);
49 $json = curl_exec($feed);
50 curl_close($feed);
51
52 $twitter_data = json_decode($json);
53
54
55
56?>
57
58
59<div style="text-align: center;"><iframe
60 width="500px"
61 height="300px"
62 frameborder="0"
63 scrolling="no"
64 marginheight="0"
65 marginwidth="0"
66 src="https://maps.google.com/maps?q=-2.99867,104.772&hl=es&z=14&output=embed">
67 </iframe>
68</div>
69
70
71
72<pre><?php print_r ($twitter_data); ?></pre>