001.
<?
002.
003.
004.
005.
header(
"Content-Type: text/html; Charset=utf-8"
);
006.
header(
"pragma: no-cache"
);
007.
header(
"Expires: Wed, 31 May 2000 14:59:58 GMT"
);
008.
header(
"Cache-control: no-cache"
);
009.
010.
011.
012.
013.
function
url_rfc3986(
$str
) {
014.
015.
return
str_replace
(
'%7E'
,
'~'
, rawurlencode(
$str
));
016.
}
017.
018.
019.
020.
021.
$twitter_url
=
'https://api.twitter.com/1/account/verify_credentials.json'
;
022.
023.
024.
025.
026.
$oauth_consumer_key
=
"Consumer key"
;
027.
$oauth_consumer_secret
=
"Consumer secret"
;
028.
$oauth_token
=
"Access Token"
;
029.
$oauth_secret
=
"Access Token Secret"
;
030.
031.
032.
$mt
= microtime();
033.
$rand
= mt_rand();
034.
$oauth_nonce
= md5(
$mt
.
$rand
);
035.
036.
$oauth_signature_method
=
"HMAC-SHA1"
;
037.
$oauth_timestamp
=
mktime
();
038.
$oauth_version
=
"1.0"
;
039.
040.
041.
042.
043.
044.
045.
046.
047.
048.
049.
050.
051.
$base_string
=
"GET"
;
052.
$base_string
.=
"&"
. url_rfc3986(
$twitter_url
);
053.
$base_string
.=
"&"
;
054.
055.
$base_string
.= url_rfc3986(
"oauth_consumer_key"
).
"%3D"
.url_rfc3986(
$oauth_consumer_key
).
"%26"
;
056.
$base_string
.= url_rfc3986(
"oauth_nonce"
).
"%3D"
.url_rfc3986(
$oauth_nonce
).
"%26"
;
057.
$base_string
.= url_rfc3986(
"oauth_signature_method"
).
"%3D"
.url_rfc3986(
$oauth_signature_method
).
"%26"
;
058.
$base_string
.= url_rfc3986(
"oauth_timestamp"
).
"%3D"
.url_rfc3986(
$oauth_timestamp
).
"%26"
;
059.
$base_string
.= url_rfc3986(
"oauth_token"
).
"%3D"
.url_rfc3986(
$oauth_token
).
"%26"
;
060.
$base_string
.= url_rfc3986(
"oauth_version"
).
"%3D"
.url_rfc3986(
$oauth_version
);
061.
062.
063.
064.
065.
066.
067.
068.
069.
$oauth_signature
=
070.
base64_encode
( hash_hmac(
071.
"sha1"
,
072.
$base_string
,
073.
url_rfc3986(
$oauth_consumer_secret
) .
"&"
. url_rfc3986(
$oauth_secret
),
074.
true
075.
));
076.
077.
078.
079.
080.
$curl
= curl_init();
081.
curl_setopt(
$curl
, CURLOPT_CONNECTTIMEOUT, 30);
082.
curl_setopt(
$curl
, CURLOPT_HEADER, false);
083.
curl_setopt(
$curl
, CURLOPT_RETURNTRANSFER, true);
084.
curl_setopt(
$curl
, CURLOPT_BINARYTRANSFER, true);
085.
curl_setopt(
$curl
, CURLOPT_URL,
$twitter_url
);
086.
087.
088.
089.
090.
$header
=
array
();
091.
$header
[] =
'Expect:'
;
092.
$header
[] =
'Authorization: OAuth '
.
093.
url_rfc3986(
"oauth_consumer_key"
).
"=\""
.url_rfc3986(
$oauth_consumer_key
).
"\","
.
094.
url_rfc3986(
"oauth_signature_method"
).
"=\""
.url_rfc3986(
$oauth_signature_method
).
"\","
.
095.
url_rfc3986(
"oauth_token"
).
"=\""
.url_rfc3986(
$oauth_token
).
"\","
.
096.
url_rfc3986(
"oauth_timestamp"
).
"=\""
.url_rfc3986(
$oauth_timestamp
).
"\","
.
097.
url_rfc3986(
"oauth_nonce"
).
"=\""
.url_rfc3986(
$oauth_nonce
).
"\","
.
098.
url_rfc3986(
"oauth_version"
).
"=\""
.url_rfc3986(
$oauth_version
).
"\","
.
099.
url_rfc3986(
"oauth_signature"
).
"=\""
.url_rfc3986(
$oauth_signature
).
"\""
;
100.
101.
curl_setopt(
$curl
, CURLOPT_HTTPHEADER,
$header
);
102.
103.
104.
105.
106.
curl_setopt(
$curl
, CURLOPT_SSL_VERIFYPEER, false);
107.
curl_setopt(
$curl
, CURLOPT_SSL_VERIFYHOST, 1);
108.
109.
110.
111.
112.
curl_setopt(
$curl
, CURLOPT_VERBOSE, true);
113.
$handle
=
fopen
(
"./debug.txt"
,
"w"
);
114.
curl_setopt(
$curl
, CURLOPT_STDERR,
$handle
);
115.
$handle2
=
fopen
(
"./ret_header.txt"
,
"w"
);
116.
curl_setopt(
$curl
, CURLOPT_WRITEHEADER,
$handle2
);
117.
$result
= curl_exec(
$curl
);
118.
119.
120.
121.
122.
123.
print
"<br>"
;
124.
125.
if
(
$result
=== false) {
126.
$json
=
'Curl error: '
. curl_error(
$curl
);
127.
}
128.
else
{
129.
echo
'Operation completed without any errors'
;
130.
$json
= json_decode(
$result
);
131.
}
132.
curl_close(
$curl
);
133.
fclose(
$handle2
);
134.
fclose(
$handle
);
135.
136.
137.
138.
139.
140.
print
"<pre>"
;
141.
print_r(
$json
);
142.
print
"</pre>"
;
143.
144.
145.
?>