I am trying to post an image to Cheezburger.com with a PHP script, and return the URL to the user. The post part works fine, I get the links, IDs etc. back in JSON format, but when I run json_decode($var, true)
it only gives me the raw JSON back. Here is the string that got fed into the script:
{
"items": [
{
"id": 6980805120,
"link": "https://api.cheezburger.com/v1/assets/6980805120",
"created_time": 1358451002,
"updated_time": 1358451002,
"media": [
{
"name": "maxW580",
"url": "https://i.chzbgr.com/maxW580/6980805120/h89D91707/",
"height": 500,
"width": 500,
"is_animated": false
},
{
"name": "maxW320",
"url": "https://i.chzbgr.com/maxW320/6980805120/h89D91707/",
"height": 320,
"width": 320,
"is_animated": false
},
{
"name": "square50",
"url": "https://i.chzbgr.com/square50/6980805120/h89D91707/",
"height": 50,
"width": 50,
"is_animated": false
}
],
"title": "JSA, UR WEBSIET IZ AWSUM. URE HIRD!",
"description": "JSA, UR WEBSIET IZ AWSUM. URE HIRD! -- This image was created by jsa005 from JSiVi using the JSiVi Meme Generator. Try it out at http://jsivi.uni.me!",
"asset_type_id": 0,
"share_url": "http://chzb.gr/10Cg1PS"
}
]
}
When I run json_decode($jsonstring, true)
on that, $jsonstring
being the variable returned by cURL containing the string above, I only get back the string I fed in. I am confused.
$fields = array(
'access_token' => $this->getToken(),
'title' => $title,
'description' => $description,
'content' => $base64data,
'anonymous' => 'true');
$url = 'https://api.cheezburger.com/v1/assets';
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
$jsonstring = json_decode($result, TRUE);