I'll be honest I'm not 100% knowledgeable with cURL
However I am looking to use it to post an tweet with an image attached to it using Twitters API.
I've got my server script setup to output any $_GET variables. However the array is outputting as blank, So I'm assuming my cURL isnt posting properly.
My PHP code is as follows :
$url = 'http://www.website.com/tweet.php';
$myvars = 'access_token=' . $access_token . '&access_token_secret=' . $access_token_secret . '&message=' . $message . '&image=' . $image;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
output($response);
The $response is returning an error from the Twtter API :
[message] => Your credentials do not allow access to this resource
If I run the URL with all credentials in it in my browser, It works without issue.
Am I missing an additional curl_setopt ?
Cheers
I don't know if this will help but I had to use cURL for Google and YouTube
I've replaced some of your my vars with yours but it may be worth a try
<?php
// init the resource
$access_token = '';
$access_token_secret = '';
$message = '';
$image = '';
$url = 'http://www.website.com/tweet.php';
$clienttoken_post = array(
"access_token" => $access_token,
"access_token_secret" => $access_token_secret,
"message" => $message,
"image" => $image
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
print_r( $json_response );
Failing that you could try the command line
curl --data "access_token=YOUR_ACCESS_TOKEN&access_token_secret=YOUR_ACCESS_TOKEN_SECRET&message=YOUR MESSAGE&image=YOUR_IMAGE" http://www.website.com/tweet.php