array en object
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"data": [
{
"name": "Besart Selmani",
"administrator": false,
"id": "100001621899610"
},
{
"name": "Kelly Bearelle",
"administrator": false,
"id": "100007926395162"
},
{
"name": "Racquel Commeyne",
"administrator": false,
"id": "100007590400350"
},
{
"name": "Eva Dhondt",
"administrator": false,
"id": "100003303273034"
},
"data": [
{
"name": "Besart Selmani",
"administrator": false,
"id": "100001621899610"
},
{
"name": "Kelly Bearelle",
"administrator": false,
"id": "100007926395162"
},
{
"name": "Racquel Commeyne",
"administrator": false,
"id": "100007590400350"
},
{
"name": "Eva Dhondt",
"administrator": false,
"id": "100003303273034"
},
Hoe kan ik nu van de id van de eerste persoon een php variabele maken?
Dit is JSON. Je kunt er in php een object van maken met de functie json_decode)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$json = '{
"data": [
{
"name": "Besart Selmani",
"administrator": false,
"id": "100001621899610"
},
{
"name": "Kelly Bearelle",
"administrator": false,
"id": "100007926395162"
},
{
"name": "Racquel Commeyne",
"administrator": false,
"id": "100007590400350"
},
{
"name": "Eva Dhondt",
"administrator": false,
"id": "100003303273034"
}
]
}';
$obj = json_decode($json);
foreach($obj->data as $data)
{
echo $data->id . '<br>';
echo $data->name . '<br>';
if($data->administrator)
echo 'Admin!<br>';
echo '<br>';
}
?>
$json = '{
"data": [
{
"name": "Besart Selmani",
"administrator": false,
"id": "100001621899610"
},
{
"name": "Kelly Bearelle",
"administrator": false,
"id": "100007926395162"
},
{
"name": "Racquel Commeyne",
"administrator": false,
"id": "100007590400350"
},
{
"name": "Eva Dhondt",
"administrator": false,
"id": "100003303273034"
}
]
}';
$obj = json_decode($json);
foreach($obj->data as $data)
{
echo $data->id . '<br>';
echo $data->name . '<br>';
if($data->administrator)
echo 'Admin!<br>';
echo '<br>';
}
?>
Nu krijg ik echter wel nog een error tijdens het connecteren met facebook.
Dit zijn de errors die ik krijg:
Warning: file_get_contents() [function.file-get-contents]: Couldn't connect to server in /home/u644995892/public_html/add.php on line 9
Warning: file_get_contents(https://graph.facebook.com/521177171307109/members/?access_token=CAACEdEose0cBAEVZBRug6eBRj6ZA2vhBCRvttDZBGzkgJSmGQZC8UNOGCE3HufcHYPprQpxhQOexFSGAMZBwOSvV3RrCPjoRedHLzC8Wo9ZAMoMTr7fTNP6phPaV2cRPKE6uAe5rPCKU5D8O8CSyNMK6c3Bsy28ROC1syKWkD8t0Ek5ehY2nc9fsCMy3DZA1OUZD) [function.file-get-contents]: failed to open stream: operation failed in /home/u644995892/public_html/add.php on line 9
dit is de code
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$link=mysqli_connect("***");
$data = file_get_contents("https://graph.facebook.com/521177171307109/members/?access_token=CAACEdEose0cBAEVZBRug6eBRj6ZA2vhBCRvttDZBGzkgJSmGQZC8UNOGCE3HufcHYPprQpxhQOexFSGAMZBwOSvV3RrCPjoRedHLzC8Wo9ZAMoMTr7fTNP6phPaV2cRPKE6uAe5rPCKU5D8O8CSyNMK6c3Bsy28ROC1syKWkD8t0Ek5ehY2nc9fsCMy3DZA1OUZD");
$array = json_decode($data, true);
$naam=$array['data'][1]['name'];
echo $naam;
?>
ini_set('display_errors',1);
error_reporting(E_ALL);
$link=mysqli_connect("***");
$data = file_get_contents("https://graph.facebook.com/521177171307109/members/?access_token=CAACEdEose0cBAEVZBRug6eBRj6ZA2vhBCRvttDZBGzkgJSmGQZC8UNOGCE3HufcHYPprQpxhQOexFSGAMZBwOSvV3RrCPjoRedHLzC8Wo9ZAMoMTr7fTNP6phPaV2cRPKE6uAe5rPCKU5D8O8CSyNMK6c3Bsy28ROC1syKWkD8t0Ek5ehY2nc9fsCMy3DZA1OUZD");
$array = json_decode($data, true);
$naam=$array['data'][1]['name'];
echo $naam;
?>
Gewijzigd op 19/05/2014 00:07:25 door Louis Deconinck
Hij krijgt geen contact met facebook.. heb je het misschien te vaak geprobeerd?
Gewijzigd op 19/05/2014 07:14:17 door Ivo P