-
Notifications
You must be signed in to change notification settings - Fork 1
/
twitterTest.php
81 lines (64 loc) · 1.88 KB
/
twitterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
* 1. Obtain Request token
* 2. Redirect the User.
* 3. Converte Request token to an access token.
*/
function post_request($url, $data){
$data = http_build_query($data);
$url = parse_url($url);
if ($url['scheme']!='http'){
die('Error: Only HTTP request are supported !');
}
$host = $url ['host'];
$path = $url['path'];
//Open a socket connection on port 80 - timeout: 30 sec
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp){
//Send request headers
fputs($fp, "POST /oauth/request_token HTTP/1.1");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Accept: */*");
fputs($fp, "Authorization:");
fputs($fp, "OAuth oauth_callback =" . $data['callback']);
fputs($fp, "oauth_consumer_key = " . $data['consumer_key']);
fputs($fp, "oauth_nonce = " . $data['nonce']);
fputs($fp, "oauth_signature = " . $data['signature']);
fputs($fp, "oauth_signature_method = " . $data['signature_method']);
fputs($fp, "oauth_timestamp = " . $data['timestamp']);
fputs($fp, "oauth_version = " . $data['version']);
$result = '';
while(!feof($fp)) {
// receive the results of the request
$result .= fgets($fp, 128);
}
}
else{
return array(
'status' => 'err',
'error' => "$errstr ($errno)"
);
}
fclose($fp);
// split the result header from the content
$result = explode("\r\n\r\n", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
// return as structured array:
return array(
'status' => 'ok',
'header' => $header,
'content' => $content
);
}
$oauth_data = array(
'callback' => "http://recrusocial.co.cc",
'consumer_key' => "uiv8cTl50JYzyzoDIrmZg",
'nonce' => "",
'signature'=> "",
'signature_method' => "",
'timestamp' => time(),
'version' => "1.0"
);
$result = post_request('api.twitter.com', $oauth_data);
?>