cache http://graph.facebook.com/[UID]/picture call? - facebook

Thanks to How can I display the users profile pic using the facebook graph api? I found out I can retrieve profile picture via
http://graph.facebook.com/[UID]/picture
but this redirects to an image like for example:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg
My first question is when I want to display this image should I do(returned from API)
<img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg" />
or should I call the api:
<img src="http://graph.facebook.com/alfredwesterveld/picture" />
Does http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg show my updated profile picture, if update my profile picture on Facebook or does show my old profile picture. I ask these question because when I could call an absolute URL(which resolves to an image immediately) I could safe myself a redirect(round-trip). I believe this could add up especially when I want to get all profile pictures from the visitors of my website.

When you want to display the picture of a user use the second method, that's the good one:
<img src="https://graph.facebook.com/[UID]/picture" alt="" />
Doing like this you'll be sure that each time you'll receive the updated picture of the user, if it was changed recently.
later edit
Related to the cache issue, if you want to save the direct urls in order to improve caching of the pictures I don't suggest doing so because those urls are changing each time a user changes the profile picture, so you might end up displaying an older picture even though the user actually changed it recently.

hi why you not use fbml tag for this?
<fb:profile-pic uid='UID' width='50' height='50'></fb:profile-pic>
EDIT
hello if you want to get photo uploaded by the user then you can get by this
$photos=json_decode(file_get_contents('https://graph.facebook.com/me/photos?access_token='.$cookie['access_token']));
foreach ($photos->data as $friend)
{
?>
<img src="<?=$friend->source?>" width="50" height="50">
<?php
}
All images uploaded by the user can be easily captured

Related

Creating a dynamic Facebook share button

I am stuck with this one...
I have a website that plays music. The page updates automatically to display the current song being played and the image of the artist. The website also allows visitors to request songs. What I want to do is allow users to then share their request on Facebook, so I have added the code below.
Initially, when you pressed the Facebook button, it would pop up iwth a box which contained all the correct info (song, artist, image, etc), but would not post correctly to Facebook (the dynamic info such as title and image would be missing). Now, recently, it doesn't even populate the pop up correctly.
I'm stuck and cannot figure out how to get this to work correctly, can anyone help me?
Thanks.
<a class="facebook" target="_blank" onclick="return !window.open(this.href, 'Facebook', 'width=640,height=300')" href="http://www.facebook.com/sharer.php?s=100&p[title]=I'm listening to <?php echo $currentSong->title . ' by ' . $currentSong->artist; ?>&p[summary]=Join me and listen right now or request your own song&p[url]=http://www.mydomain.com&p[images[0]=<?php echo $largeimg; ?>"><img src="http://www.mydomain.com/new/images/facebook.png" width="32" height="32" border="0" style="padding-top:5px; padding-right:4px "></a>
Actually, you should only add the URL as parameter (url encoded) to the sharer.php:
<img ... />
It automatically takes the Open Graph data from the shared URL, see this page: http://ogp.me/
I assume all the other parameters are deprecated, at least it did not work for me some months ago. The only thing you could try is to encode all data with the PHP function "urlencode" - but i would suggest using the correct way and implement Open Graph correctly. That way you can even just take the URL, put it on Facebook manually and it will take the correct data.
If the content is completely dynamic, you should consider using Open Graph Actions: https://developers.facebook.com/docs/opengraph/
Or if that is too complicated, use the FB.ui feed dialog:
https://developers.facebook.com/docs/reference/dialogs/feed/
...but don´t forget to include the JavaScript SDK:
https://developers.facebook.com/docs/javascript/quickstart

Linking directly to Facebook's stored og:image for a particular URL?

It's pretty slick that Google lets you link to a website's favicon, simply like this:
http://www.google.com/s2/favicons?domain=www.stackoverflow.com. This is great because you can use this as the src of an image.
Anyone know of a similar way to link to the image defined in the og:image tag for a given web page -- a 3rd party URL, and not a Facebook-hosted "Page"? This would be really handy, to do something like (and I'm making this up):
<img src="https://graph.facebook.com/www.stackoverflow.com/og:image" />
Yes this can be done using open graph.
https://graph.facebook.com/[userId]/picture or
https://graph.facebook.com/[pageId]/picture
For example:
UserId
https://graph.facebook.com/4/picture (Mark Zuckerberg's profile picture) or
PageId
https://graph.facebook.com/40796308305/picture (Coca Cola's profile picture) or
https://graph.facebook.com/cocacola/picture

Render facebook open graph preview in page

When using the javascript sdk the app opens a dialog with a link, facebook will fetch some sort of a display for that link, based on the og tags in it, and will put it inside an element with id "UIStoryAttachment".
Is there a way to somehow produce the same UIStoryAttachment display inside a container element of my choice? like, for example something similar to:
<div id="storyContainer">
<div class="fb-story" data-url="MY_PAGE_URL"></div>
</div>
And then:
FB.XFBML.parse(document.getElementById("storyContainer"));
This of course does not exist, but is there anything similar in anyway?
Thanks.

Facebook graph profile image unreliable

I am trying to display a comments feed on my Facebook application, I am loading in an array of Facebook user ids and an associated comment, to display the users profile picture, I am using the following snippet:
<?php echo '<img src="http://graph.facebook.com/'.$c->_user.'/picture'" />; ?>
This works fine, and gets the image, however, if I refresh my page, I get some if not all of the thumbnails will not be loaded, refresh again and they'll always be there, it's pretty consistent that when I refresh they'll appear, next time they won't and so on.
Should I be dealing with this differently ? I know that in the browser the graph API redirects to the actual image, so maybe this is what's causing my browser to sometimes not display them, say if, it took too long to load the image ?
The issue is probably what genesis φ says says, just a temporary issue on Facebook's end. But to add on to his suggestions, you might try serving the image from https:. Alternatively, you can get the full, redirect-less picture URL from the user FQL table.
It's probably just their temporary issue. If you want to be sure, download them for the first time and you could "host" them more reliabily

How does Facebook detect images when adding a link?

When you add a link to your Facebook page, after some processing, Facebook presents you a next/prev button to choose an image linked to the url your are inserting.
Obviously, Facebook reads the html-page and displays the images found on the url you insert.
Does anyone knows what algorithm Facebook uses to decide what images to show ?
If I insert a link to : http://www.staplijst.be/lachende-wandelaars-aalter-aktivia-003.asp, only 11 images are detected. The one I want, the one at the top right corner, is not included in the list.
If I insert a link to http://www.staplijst.be/stichting-kennedymars-rijsbergen-zundert-nederland-knblo-nl-81996.asp, 19 images are displayed (including the one I want (the one at the right top corner of the text area).
Both pages are build using asp code but are functionally the same.
I thought that it has something to do with the image size, but can't find any deciding factor there.
I will investigate some furhter, because if I know what Facebook is looking for, I can make sure that the correct images are included on the page (since they are dynamic pages build with classic asp).
But if anyone has any idea ? Help would be appreciated.
This looks like a duplicate of:
Facebook Post Link Image
Use <link rel="image_src" href="abs_url_of_your_image">
My guess, is that FB hides repeated images - 'couse a repeated image normally indicates a design-element (not content). When you post a link, only images related to that articles content, are relevant.
So; make sure your image only appears once, and see if it helps!
I am not familiar with the way Facebook did it, but I can tell you how I would do it.
Establish web request to desired url
Parse resulted web response with regular expression, that looks for <img src="" />