2 //From https://stackoverflow.com/questions/3295466/another-twitter-oauth-curl-access-token-request-that-fails/3327391#3327391
3 function generateSingature($params){
7 // encode params keys, values, join and then sort.
8 $keys = _urlencode_rfc3986(array_keys($params));
9 $values = _urlencode_rfc3986(array_values($params));
10 $params = array_combine($keys, $values);
11 uksort($params, 'strcmp');
13 // convert params to string
14 foreach ($params as $k => $v) {$pairs[] = _urlencode_rfc3986($k).'='._urlencode_rfc3986($v);}
15 $concatenatedParams = implode('&', $pairs);
17 // form base string (first key)
18 $baseString= "GET&"._urlencode_rfc3986(request_token
)."&"._urlencode_rfc3986($concatenatedParams);
19 // form secret (second key)
20 $secret = _urlencode_rfc3986(secret
)."&";
21 // make signature and append to params
22 $params['oauth_signature'] = _urlencode_rfc3986(base64_encode(hash_hmac('sha1', $baseString, $secret, TRUE)));
28 $msg_len = decoct(strlen($msg) +
10);
30 $consumer_key = "-------";
31 $access_token = "-------";
32 $random_value = str_replace("=", "2", base64_encode(rand(10000000000,1000000000000)));
34 $method = "HMAC-SHA1";
36 $signature = generateSingature(array(
37 "oauth_version" => "1.0",
38 "oauth_nonce"=>"$random_value",
39 "oauth_timestamp" => "$timestamp",
40 "oauth_consumer_key" => "$consumer_key",
41 "oauth_signature_method" => "HMAC-SHA1"
44 $curl = curl_init("https://api.twitter.com/1.1/statuses/update.json");
45 curl_setopt($curl, CURLOPT_HTTPHEADER
, array("Accept: */*", "Connection: close","User-Agent: VerniyXYZ-CURL" ,"Host: api.twitter.com",
46 "Content-Type: application/x-www-form-urlencoded;charset=UTF-8",
47 "Content-Length: $msg_len", "Host: api.twitter.com",
50 OAuth oauth_consumer_key='$consumer_key',
51 oauth_nonce='$random_value',
52 oauth_signature='$signature',
53 oauth_signature_method='$method',
54 oauth_timestamp='$timestamp',
55 oauth_token='$access_token',
60 curl_setopt($curl, CURLOPT_POST
, 1);
61 curl_setopt($curl, CURLOPT_POSTFIELDS
, "include_entities=true&status=$msg");
62 var_dump(curl_exec($curl));