https://developers.facebook.com/docs/graph-api/reference/user/albums/
HTTP request is
GET /v12.0/{user-id}/albums HTTP/1.1
Host: graph.facebook.com
To test/use http
Search fb api test
in google
https://developers.facebook.com/tools/explorer/
- Add user_photos permission, in "Permissions" (bottom right)
- "Generate Access token"
- Copy me?fields=albums and submit. (if it is for posts during a specific period, use me/posts?fields=message,created_time&since=1631146270&until=1631405470 , to get time stamps in this case use this service )
- If in APP, copy {user-id}/albums and submit
The result will be like
{
"data": [],
"paging": {}
}
***Usually 25 albums will be shown in data
.in paging
it will show next
and previous
links.
User the next
link to fetch next 25 until next
key is not present in paging
fbAlbums.php
is made by copying the return values and making each return value an array element.
it then sorts based on album names.
if there are multiple albums with same names, it will show (multiple #n) as suffix
//echo "<pre>".print_r($fbAlbums,true)."</pre>";
$albumNo = 0;
$albumNames = array();
$duplicateAlbums = array();
function myfunction($value, $key)
{
//echo "The key $key has the value $value \n";
$jsonVal = json_decode($value);
array_walk($jsonVal->data, function($val){
global $albumNames,$albumNo,$duplicateAlbums;
//$albumNo++;
$arrayKey = $val->name;
if(isset($albumNames[$arrayKey]))
{
if(isset($duplicateAlbums[$arrayKey]))
{
$duplicateAlbums[$arrayKey]+=1;
}
else
{
$duplicateAlbums[$arrayKey] = 1;
}
$arrayKey .= " (multiple {$duplicateAlbums[$arrayKey]})";
}
$albumNames[$arrayKey] = $val->id;
//echo $albumNo.",".$val->name.",https://www.facebook.com/media/set/?set=a.".$val->id."<br />";
});
}
// Input array
$arr = array("a"=>"yellow", "b"=>"pink", "c"=>"purple");
// calling array_walk() with no extra parameter
array_walk($fbAlbums, "myfunction");
$sortedAlbumNames = ksort($albumNames);
array_walk($albumNames, function($val,$key){
global $albumNames,$albumNo;
$albumNo++;
$csvSeperator = ";";
echo '"'.$albumNo."\"".$csvSeperator."\"".$key."\"".$csvSeperator."\"".$val."\"".
//"\"https://www.facebook.com/media/set/?set=a.".$val."\"".$csvSeperator."\"fb://media/set/?set=a.".$val."\
"<br />";
});
|
|