I want use php curl
with oauth
to get the JSON data from twitter
. Here is my code. return na error message "error":"Timestamp out of bounds"
.
I want to know, how to make a correct twitter api curl with oauth?
what is
oauth_consumer_key
,oauth_token
,oauth_nonce
,oauth_signature
? am I right?how to solve
"error":"Timestamp out of bounds"
?how about my
curl_setopt
method?
In many way, I would like to use this php curl
to decode other twitter api(changed url). Thanks a lot.
$callback="<callback url>";
$consumer_key="<Consumer key>";
$consumer_secret="<Consumer secret>";
$oauth_token="<Access Token (oauth_token)>";
$oauth_signature="<Access Token Secret (oauth_token_secret)>";//these key word in my api panel
$time = mktime(date("Y-m-d H:i:s"))-86400;
$url = "https://api.twitter.com/1/friends/ids.json?";
$url .= "user_id=<user id>";
$url .= "&realm=".urlencode($callback)."";
$url .= "&service_provider_id=11";
$url .= "&oauth_consumer_key=".$consumer_key."";
$url .= "&oauth_token=".$oauth_token."";
$url .= "&oauth_nonce=".$consumer_secret."";
$url .= "&oauth_signature_method=HMAC-SHA1";
$url .= "&oauth_timestamp=".$time."";
$url .= "&oauth_version=1.0";
$url .= "&oauth_signature=".$oauth_signature."";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: api.twitter.com'));
$json = curl_exec($ch);
curl_close ($ch);
$data = json_decode($json, true);
print_r($json);