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
Related
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'];
ive set the required permissions and gotten the path ie me/photos this displays:
{
"data": [
{
"id": "78768",
"from": {
"name": "Dai beckham",
"id": "135656456"
},
"picture": "link here",
"source": "link here",
"height": 540,
"width": 720,
"images": [
{
"height": 720,
"width": 960,
"source": "link here"
},
i then try echoing the image paths like echo $user_graph['data']['source']; but im getting an error
"Notice: Undefined index: source in A:file-name.php on line 12"
i have no idea where im going wrong. thanks in advance.
You need to convert the response into an array before you can access it like that.
Currently it's in JSON format. You can use the native json_decode() function to convert it for you.
$array = json_decode($response, true);
$source = $array['data']['source'];
$array = json_decode($response, true); //it will provide array
$source = $array['data']['source']; and access it now
Simply fetch from this url
http://graph.facebook.com/ankit.varia/picture
type your name instead of mine ankit.varia(me)= (your)
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; ?>
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
I want to get details of public photo of any user's facebook account.
here is my image url : http://www.facebook.com/photo.php?fbid=346729048691589&set=a.346719012025926.83282.100000634900314&type=1&l=f48e02a2e3&permPage=1
and i want details of this photo so i have generated url like : http://graph.facebook.com/346729048691589/albums but getting data as blank array. and also in my album all the photos are public.
I read this url : How to use Facebook Photos in an iPhone App? and example getting the result and i want the same result also but some how i am not getting it.
And i read that we don't require access token if we want to use any public details of facebook but here i am not getting the result.
So Can any one help me?
Thanks
How to get data(json array) of facebook public photo by using photo url?
What I did was to take the fbid from the querystring of your image url in your question. Then I went to the graph API explorer tool and brought it up. See link: https://developers.facebook.com/tools/explorer?method=GET&path=346729048691589
When I did that it returned:
{
"id": "346729048691589",
"from": {
"name": "Development SandBox",
"id": "100000634900314"
},
"picture": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_s.jpg",
"source": "http://sphotos.xx.fbcdn.net/hphotos-snc7/421606_346729048691589_216224001_n.jpg",
"height": 469,
"width": 700,
"images": [
{
"width": 700,
"height": 469,
"source": "http://sphotos.xx.fbcdn.net/hphotos-snc7/s720x720/421606_346729048691589_216224001_n.jpg"
},
{
"width": 180,
"height": 120,
"source": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_a.jpg"
},
{
"width": 130,
"height": 87,
"source": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_s.jpg"
},
{
"width": 75,
"height": 50,
"source": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_t.jpg"
}
],
"link": "http://www.facebook.com/photo.php?fbid=346729048691589&set=a.346719012025926.83282.100000634900314&type=1",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
"created_time": "2012-02-10T11:14:42+0000",
"position": 2,
"updated_time": "2012-02-10T11:14:43+0000",
"type": "photo"
}