zencoder notifications json - php

I'm working with some videos on PHP, using zencoder to encode the videos, save them on s3 and then notify my site back when it's all done.
Everything is working until I have to process the notifications returned as json and pull out the new url to the saved video.
this:
$notification = $zencoder->notifications->parseIncoming();
if($notification->job->state == "finished")
{
$encode_id=$notification->job->id;
}
works fine. I just need some pointers on accessing the url.
The notification is sent as:
{
"output": {
"frame_rate": 30.0,
"label": "video_id_",
"total_bitrate_in_kbps": 3115,
"md5_checksum": null,
"channels": "2",
"audio_codec": "aac",
"duration_in_ms": 4225,
"video_codec": "h264",
"url": "http://my_url/597bd3592bf4a9d70f04dc676c44de6d.mp4",
"thumbnails": [{
"label": null,
"images": [{
"url": "http://my_url/_key__0000.png",
"format": "PNG",
"dimensions": "640x360",
"file_size_bytes": 482422
}]
}],
"video_bitrate_in_kbps": 3052,
"width": 640,
"format": "mpeg4",
"height": 360,
"audio_sample_rate": 44100,
"state": "finished",
"audio_bitrate_in_kbps": 63,
"id": 41424918,
"file_size_in_bytes": 1625847
},
"input": {
"frame_rate": 30.0,
"total_bitrate_in_kbps": 3867,
"md5_checksum": null,
"channels": "2",
"audio_codec": "aac",
"duration_in_ms": 4167,
"video_codec": "h264",
"video_bitrate_in_kbps": 3764,
"width": 640,
"format": "mpeg4",
"height": 360,
"audio_sample_rate": 44100,
"state": "finished",
"audio_bitrate_in_kbps": 103,
"id": 22371764,
"file_size_in_bytes": 2028809
},
"job": {
"created_at": "2012-07-14T22:25:08Z",
"test": true,
"updated_at": "2012-07-14T22:25:47Z",
"submitted_at": "2012-07-14T22:25:08Z",
"pass_through": null,
"state": "finished",
"id": 22377083
}
}
but something like: $video_file=$notification->output->url; doesn't.
What am I missing?

If you don't want to use the parseIncoming method...
Use:
$notification = json_decode(trim(file_get_contents('php://input')), true);
as apposed to:
$notification = $zencoder->notifications->parseIncoming();
The second paramater of 'true' will format the results as an array as apposed to an object. From there, you can access all the values like:
$notification['output']['file_size_in_bytes'];
The parseIncoming method will return a stdClass, so referencing values within it is done with:
$notification->key

Related

json decode call photo telegram api

i want get photo file id.
file_get_contents('php://input'):
{
"update_id": 399206890,
"message": {
"message_id": 149,
"from": {
"id": 81777999,
"is_bot": false,
"first_name": "#goldenguardbot",
"last_name": "✅",
"username": "amirntm",
"language_code": "en-US"
},
"chat": {
"id": 81777999,
"first_name": "#goldenguardbot",
"last_name": "✅",
"username": "amirntm",
"type": "private"
},
"date": 1507643430,
"photo": [
{
"file_id": "AgADBAADpaoxG6lZ6VIeePTlKxaJsl3X-RkABPbjyThHJgF7FLwBAAEC",
"file_size": 1639,
"file_path": "photos/file_4.jpg",
"width": 90,
"height": 72
},
{
"file_id": "AgADBAADpaoxG6lZ6VIeePTlKxaJsl3X-RkABIrarvPZGVNGFrwBAAEC",
"file_size": 22230,
"width": 320,
"height": 256
},
{
"file_id": "AgADBAADpaoxG6lZ6VIeePTlKxaJsl3X-RkABKFhu79tL5EBF7wBAAEC",
"file_size": 95422,
"width": 800,
"height": 640
},
{
"file_id": "AgADBAADpaoxG6lZ6VIeePTlKxaJsl3X-RkABGzlLqe_Yv0PFbwBAAEC",
"file_size": 172689,
"width": 1160,
"height": 928
}
]
}
}
i want file id how get it?
for example:
$update->message->photo->file_id;
The "photo" section is an array. Square brackets in JSON ([]) indicate an indexed array. Curly braces ({}) indicate an object or associative array, depending on how you choose to parse it in PHP.
You don't mention which "file_id" you want, but assuming you want the first:
$update = json_decode(file_get_contents('php://input'));
echo $update->message->photo[0]->file_id;
You need to decode it to PHP object/array, and get photos in $update->message->photo, that will be array of one photo in different resolution, the latest one always be largest, so you can use end($photos) to get it, and file_id is corresponding file identity.
Code example:
$json = file_get_contents('php://input'):
$update = json_decode($json);
$photos = $update->message->photo;
$photo = end($photo);
$file_id = $photo['file_id'];

Facebook - Get & Display me/og.likes in Video application

Have built an video app that publish user actions towards Facebook.
In this app i have implemented an "Favorite" function that i have hooked up towards a basic open graph action "og.like"
I want to be able to display video's that user liked and apply my own styling to that.
Basically i want to display "Title" "Url" & "Image"
So i use the PHP-SDK towards authored user with active access token and execute
$response = $facebook->api(
'me/og.likes',
'GET'
);
// handle the response
How do i now sort out my correct fields and display them ?
Am not hardcore at either php or javascript but will be able to sort this out if i just can get a little push in the right direction. Like just showing the raw data
Update
Finally a little progress, adding
print_r ($response);
Will write out the raw data, Now i know that am on the right way.
Array returned
{
"data": [
{
"id": "123",
"from": {
"name": "Mathias",
"id": "APP_ID"
},
"start_time": "X",
"end_time": "X",
"publish_time": "X",
"application": {
"name": "APP_Name",
"namespace": "",
"id": "321"
},
"data": {
"object": {
"id": "139",
"url": "Url to like",
"type": "video.tv_show",
"title": "title"
}
},
"type": "og.likes",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
},
And then the next..
From every app "like" i would like to display Url ,Title & Image
From what i understand so far my main problem is that this is nested arrays, Did try with single level arrays and there i did manage to display correct data just by
echo $response[name];
So how do i digg in and loop this around, All tips are welcome,
{
"id": "139",
"url": "url",
"type": "video.tv_show",
"title": "titke",
"image": [
{
"url": "image_URL",
"secure_url": "image_URL",
"type": "image/jpg",
"width": 1024,
"height": 576
}
Here's an example:
<?php foreach ( $response['data'] as $data ): ?>
<?php $Object = $data['data']['object']; ?>
<?php echo $Object['title']; ?><br />
<?php endforeach; ?>

How to Parse Image from JSON in facebook graph api

Bellow JSON contain my fan page info in the json format.I tried getJson in the jquery but it didn't work for me
{
"about": " One who does something \n\n",
"description": "Doers Web development\nDoers Software Development\nDoers Graphics design\nDoers Hardware & Networking\nDoers Mobile Application Development",
"is_published": true,
"location": {
"street": "",
"city": "Colombo",
"country": "Sri Lanka",
"zip": ""
},
"phone": "+94773633412",
"talking_about_count": 686,
"username": "DoersIncorporation",
"website": "http://www.doers.lk",
"were_here_count": 0,
"category": "Computers/technology",
"id": "397319800348866",
"name": "Doers Inc",
"link": "https://www.facebook.com/DoersIncorporation",
"likes": 767,
"cover": {
"cover_id": 398352273578952,
"source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-snc7/s720x720/484190_398352273578952_36222530_n.png",
"offset_y": 0
}
}
What i want to know is how to parse cover image from it using php and jquery ???
Save the JSON to a variable:
var x = theJSON
x.cover.source
will return the url
Fiddle

Parse Nested JSON With JQuery

I'm new to JSON and really struggling with this. I've read countless other posts and web pages but can't seem to figure it out.
I'm using PHP to output JSON (from data from the database) with this code:
header('Content-type: application/json');
echo json_encode($data);
Here is the JSON:
{
"x0": {
"id": "1",
"name": "Rob",
"online": "1",
"gender": "m",
"age": "29",
"height": "5'8''",
"build": "Average",
"ethnicity": "White",
"description": "Art geek person",
"looking_for": "Anything",
"image": "4fs5d43f5s4d3f544sdf.jpg",
"last_active": "29-06-11-1810",
"town": "Manchester",
"country": "UK",
"distance": 0.050973560712308
},
"x1": {
"id": "2",
"name": "Dave",
"online": "1",
"gender": "m",
"age": "29",
"height": "5'8''",
"build": "Average",
"ethnicity": "White",
"description": "Art geek person",
"looking_for": "Anything",
"image": "4fs5d43f5s4d3f544sdf.jpg",
"last_active": "29-06-11-1810",
"town": "Manchester",
"country": "UK",
"distance": 0.050973560712308
}
}
I think the problem I'm having is that the JSON is nested(might be wrong there)?.
This is the JQuery:
function fetchProfiles() {
var url='http://url.com/here';
var i = 0;
var handle = 'x'.i;
$.getJSON(url,function(json){
$.each(json.results,function(i,profile){
$("#profiles").append('<p><img src="'+profile.handle.image+'" widt="48" height="48" />'+profile.handle.name+'</p>');
i++;
});
});
}
Any ideas or suggestions appreciated!
Thanks!
i think that the problem is that you call $.each on json.results (if the json is exactly what you showed us).
you sholud do:
$.each(json,function(i,profile){
$("#profiles").append('<p><img src="'+profile.image+'" widt="48" height="48" />'+profile.name+'</p>');
});
look at the fiddle here: http://jsfiddle.net/ENcVd/1/ (it alerst the image property of you json object)

download facebook photos using graph API in JSON Format?

Hi using graph API i am able to get the photos of my albums, now i want to download all the photos in the album to my computer. it returns data in JSon format, how can i filter only the Urls of the images from that json and then download all photos from that url
my json is some like this format
{
"data": [
{
"id": "1140894483853",
"from": {
"name": "Muhammad Asghar",
"id": "1272156814"
},
"tags": {
"data": [
{
"id": "1272156814",
"name": "Muhammad Asghar",
"x": 52.6,
"y": 29.538,
"created_time": "2009-08-20T07:46:50+0000"
}
]
},
"picture": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v3356/171/103/1272156814/s1272156814_30392128_5890712.jpg",
"source": "http://a4.sphotos.ak.fbcdn.net/photos-ak-snc1/v3356/171/103/1272156814/n1272156814_30392128_5890712.jpg",
"height": 604,
"width": 498,
"images": [
{
"height": 604,
"width": 498,
"source": "http://a4.sphotos.ak.fbcdn.net/photos-ak-snc1/v3356/171/103/1272156814/n1272156814_30392128_5890712.jpg"
},
Please anyone help.
You can use JsonDecode: JsonDecode
assume your json string is in a $data variable, you can try something like this:
<?php
var_dump( json_decode($data));
?>
if you look at the source code of the page you'll have a pretty clear idea of how the json is structured, and you can easly use a foreach statement to get only the urls you need

Categories