Reputation: 15724
I have been using the facebook grap to pull photo albums from public "pages" and display the photos, but today it stopped working (and not just on my PC, it has been verified by others)
I've been hitting the graph api without a token and without any SDK, just constructing graph.facebook.com
links and using the returned json.
At first I thought the problem was occuring only on Chrome but now I'm not so sure. I've confirmed that spoofing the user agent has no effect and I've recently discovered that deleting Facebook.com cookies resolves the problem.
Now, I can't foribly delete other people's cookies, so I'd love another fix, or at least an explanation.
The graph calls look like https://graph.facebook.com/{{albumID}}
Heres an example: https://graph.facebook.com/203416696378870
Error recieved
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException",
"code": 104
}
With no facebook.com cookies, I get the expected output.
"id": "203416696378870",
"from": {
"id": "186646504722556",
"category": "Musician/band",
...
Facebook Cookies Before removing
I still don't understand why Facebook cookies would suddenly break my code.
I couldn't find any documented change in Facebook's platform updates or Chrome Releases which might explain this behavior.
Of course, I cannot forcibly remove cookies from users of all the sites which use my code, and I am unhappy with how brittle this apparently makes it.
Does anyone have any additional insight into this problem, and what specifically in the facebook.com cookies messes with the graph api calls?
Is there anyway to prevent this from happening?
Upvotes: 3
Views: 3695
Reputation: 540
it's weird that facebook is asking the access token, however if you simply need only the pictures from the album, this works for me:
https://graph.facebook.com/YOUR_ALBUM_ID/photos?fields=picture&limit=500
the fields=picture statement is mandatory for it to work properly.
And you might find this usefull
if (empty($_GET['album'])) {
//get all albums of page
$graph_url = "https://graph.facebook.com/PressPlayPrague/albums?fields=id,link,name,cover_photo&limit=500";
$albums = json_decode(file_get_contents($graph_url));
$counted = sizeof ($albums->data); // get the number of albums for later use
//output all albums of given page
for($c=0; $c<$counted; $c++){
echo ("<div class='wrapper' <a href='?album=".$albums->data[$c]->id."'><div class='stack'><div style='width:180px; height:120px; display:inline-block; background-image:url(https://graph.facebook.com/".$albums->data[$c]->id."/picture?width=300&height=200); background-repeat:no-repeat;'> </div></div><div class='caption'>".$albums->data[$c]->name."</div></a></div>");
};
}else{
//get the album pictures replace the $_GET[album] with specific ID and remove the if clause to get only one album
$pic_url = "https://graph.facebook.com/".$_GET[album]."/photos?fields=picture&limit=500";
$pictures = json_decode(file_get_contents($pic_url));
$countpic= sizeof ($pictures->data); // get the number of pics for later use
for($p=0; $p<$countpic; $p++){
echo ("<img style='width:250px; max-height:167px;'src='https://graph.facebook.com/".$pictures->data[$p]->id."/picture' alt='".$pictures->data[$p]->id."'>");
};
}
?>
Upvotes: 2
Reputation: 1
Changing IP address finally solved all issues, don't know if cookie deleting was necessary at all, but directly after IP address changed, all worked fine, in all browsers In one browser I never deleted cookies and also there all working after page reload
Btw. Calling the graph link directly still results in funny things, IE says page not found, safari oath, Firefox shows data, all present website incl album fine, same album I'd like used for direct graph link
Upvotes: 0
Reputation: 1
I deleted all Cookies, after that I was not able to call the graph link,
next i go to facebook site, switched to my page account, reloaded the graph link, and it worked
but calling script from my webserver does not work at all
IE10, FF20, latest chrome, all same result
Upvotes: 0
Reputation: 74420
I don't know how you try to retrieve data, but if i use getJSON, it works for me:
<a id="facebook-graph-link">TEST FACEBOOK</a>
<script>
$(function(){
$( "#facebook-graph-link" ).on( "click", function(e) {
e.preventDefault();
var url = "http://graph.facebook.com/203416696378870";
$.getJSON( url, function( data ) {
console.log(data);
});
});
});
</script>
Upvotes: 1