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)
Related
I'm trying to get data from the following JSON file using PHP
I Want To Get All URls (link) ,
http://www.google.com
http://www.bing.com
Json
Here is what I tried
PHP
Thanks
You cannot access an object property using a number, it must be a string.
It is much easier to output json_decode as an array, and access properties that way. To do this, put true as the second parameter.
<?php
$json = '
{
"news": {
"name": "yahoo",
"url": "https://yahoo.com"
},
"links": [
{
"id": "1",
"url": "https://google.com"
},
{
"id": "2",
"url": "https://bing.com"
}
]
}';
$decode = json_decode($json, true);
echo $decode['links'][0]['url'];
I have a problem with starting a project of 'clan community statistics'.
I have a URL with the API of the statistics, and i want to show this in an array using a simple html dom parser. I want to get this effect:
{
"status": "ok",
"count": 1,
"data": {
"1": {
"members_count": 100,
"description": "Закрытый клан...",
"description_html": "<p>Закрытый клан....\n</p>",
"created_at": 1293024672,
"updated_at": 1375930001,
"name": "Wargaming.net",
"abbreviation": "WG",
"emblems": {
"large": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64.png",
"small": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_24x24.png",
"medium": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_32x32.png",
"bw_tank": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64_tank.png"
},
"clan_id": 1,
"members": {
"196632": {
"created_at": 1293126248,
"role": "private",
"updated_at": 1375930001,
"account_id": 196632,
"account_name": "Wrobel"
},
"18458": {
"created_at": 1360836543,
"role": "diplomat",
"updated_at": 1375930001,
"account_id": 18458,
"account_name": "alienraven"
},
"3100": { ....
}
},
"motto": "Орлы! Орлицы!",
"clan_color": "#e18000",
"owner_id": 1277137
}
}
}
My code
include('simple_html_dom.php');
$html = file_get_html('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659');
...?
What should I do next to prepare an array and display it in the way which I want on my web page? Is there someone obliging to explain it to me? please.
Greetings Mary
try this
<?php
// example of how to modify HTML contents
include('../simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659');
$data = json_decode($html);
echo "<pre>";
print_r($data);
?>
I see the data is in json format. Just use:
$json = file_get_contents('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659'); //gets the json
$obj = json_decode($json); //decode the json into object or array. You'll get an object
var_dump($obj); //view the object. Parse the object the way you want to.
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; ?>
Im tring to show a list of articles on my site with a authour, date and comments field below the article so that users can see the number of comments for an article before even opening it.
The coments are from facebook and im using the graph api which returns the following JSON code per article, how do i get the total number of comments from this? Thanks
I have tried json_decode but the arrays am getting are all with count zero.
{
"http://www.withinzambia.com/technology-and-it/your-modem-isnt-that-fast.html": {
"comments": {
"data": [
{
"id": "10151004341202332_23086817",
"from": {
"name": "Cindi Mutale",
"id": "1045450015732187"
},
"message": "Glad someone finally pointed this out.",
"can_remove": false,
"created_time": "2012-07-02T19:46:58+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "10151002332_23094740",
"from": {
"name": "Chanda Mike",
"id": "1000034452054679"
},
"message": "my modem is 7mbps, so that's not 7MB per second?",
"can_remove": false,
"created_time": "2012-07-03T13:51:24+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "10151004341202332_23094782",
"from": {
"name": "Precious Chulu",
"id": "100242343243281187"
},
"message": "The max for the modem in the picture is 7mbps, which is actually about 900kb when you divide by 8, so you will never download at more than 1mb per second with these modems even when MTN or Airtel upgrades the network.",
"can_remove": false,
"created_time": "2012-07-03T13:57:56+0000",
"like_count": 0,
"user_likes": false
}
],
"paging": {
"next": "https://graph.facebook.com/10151004341202332/comments?value=1&redirect=1&limit=25&offset=25&__after_id=10151004341202332_23094782"
}
}
}
}
<?php
...
$count = 0;
$array = json_decode($input, true);
foreach($array AS $website) {
$count += count($website['comments']['data']);
}
...
?>
$count is answer.
Bonus :)
$jsonArr = ' ..your JSON array.. ';
$decodedArr = json_decode($jsonArr);
$num_comments = count($decodedArr->{'http://www.withinzambia.com/technology-and-it/your-modem-isnt-that-fast.html'}->comments->data);
echo $num_comments;
tested and works.
be aware that if you load your JSON into a string, like i did here, single quotes will need to be escaped.
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