I've created a Twitter Application to auto-post to my Twitter account. So, I don't need to authorize new users.
I've already set access level to read/write, and received an access token. I've used the OAuth Tool in the application to generate a cURL command:
curl --request 'POST' 'https://api.twitter.com/1/statuses/update.json' --data 'status=Maybe+he%27ll+finally+find+his+keys.+%23peterfalk' --header 'Authorization: OAuth oauth_consumer_key="...", oauth_nonce="97fad626790e8e5988d4a06cfd47fa74", oauth_signature="...", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1364161424", oauth_token="...", oauth_version="1.0"' --verbose
Above the command, it says:
Important: This will only be valid for a few minutes. Also remember the cURL command will actually execute the request.
I assume that this will work in a linux terminal.
I'd like to know how to translate this into a PHP cURL command. Here's what I've tried. Note that value of $DST is the value of "DST" in https://dev.twitter.com/docs/auth/authorizing-request; it is also equal to the value of the string after --header 'Authorization:
in the cURL command in the OAuth tool.
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
data => 'status='.urlencode($status),
header => 'Authorization: '.$DST
)
));
$resp = curl_exec($ch);
curl_close($ch);
But the value of $resp
is:
{
request: "/1/statuses/update.json",
error: "Could not authenticate you."
}
Is there something I'm doing wrong? Note that the OAuth Tool said that the cURL command would actually work. So I think it's just a matter of figuring out how to arrange the cURL in PHP. I'm not very familiar with it. Also note that I want to avoid using the OAuth libraries if I can. I feel like there should be a much more light-weight solution to this than to install a whole library.