Facebook app: Random quotes not refreshing on each page load - facebook

I have a Facebook app written in php that will display random quotes on your profile.
The box does not appear to update, it looks like it did when it was originally added.
I want to update the profile boxes on each page load (refresh), and not by a user action like clicking a link.
Any idea what is the problem and how to solve it?

This is how I did it for The Office Quotes application:
Put the random quote inside an image (many options to do this in PHP, I used the GD and Image Functions at http://us2.php.net/manual/en/ref.image.php to create a JPG containing the quote).
Accessing this dynamic image in a browser gives you a different random quote each time you refresh.
On the Facebook profile box or tab, simply link this image.
However, Facebook caches the image the first time it's loaded, so it never updates!
To force Facebook to update, you must update Facebook's image cache for the image's URL using the API function fbml.refreshImgSrc which is now accessed via the URL http://api.facebook.com/methods/fbml.refreshImgSrc and requires the access_token parameter like all other API requests. There was an announcement some time ago that this function was being deprecated, but the decision was reversed!
Setup the cache refresh code to run regularly. You can do this on a scheduled task (i.e. a cron job) or on each pageview in the application, or any other way you can think of that will cause the method to be run with the relative frequency the image will be requested by a user.
I also linked the image in the profile to a page in the app that would continually reload a new random image. Users generally would click to this page (which would refresh the image cache on each load) and they get the illusion that the image updates constantly.
Another illusion that I like even better is to add a 'Refresh' link in the profile box/tab that links to a script that refreshes the image cache and immediately returns to the user's profile, so that it actually appears to just be refreshing the profile box/tab.
Enjoy!

Profile content is cached by Facebook and does not connect to your server on every page load. This has always worked like this. No javascript runs on load/automatically, so you can't have a new quote displayed on page load.
What you can do is put a bunch of quotes in the profile content and us the fb:random tag to display a random quote on page load from the random option list. Periodically you can run a script to update the set of quotes in the user profile. If quotes are not unique to each user, you should use fb:ref handles so you just have to update the handle content, not each user's profile. Just put the ref handle in the user's profile.

I'm confused. Profiles boxes are all but gone. You shouldn't be developing anything for a profile box right now - it's just gonna disappear any day now anyway.
And even when profile boxes were still a suggested integration point, you couldn't update them in the way you are wanting to.

Related

Callback from Facebook app as a tab app on multiple pages

Salon owners can create an account with their salon information on our platform and they get a page that they can use as a tab app.
I want to be able to serve all these pages from one app instead of having to install each one seprately and I also want to make the life of the salon owner easier by helping them to install the tab.
I know about the link I can create to help them install the app and I know that when a visitor visits the app that facebook will send the page ID. So far so good.
https://developers.facebook.com/docs/appsonfacebook/pagetabs/
But how do I make sure that when the salonowner follows the link to install the app that I get the page ID back (through callback or other) so that I can register which page ID belongs to which salon account.
I've read sone 2011 article about a callback but I can't find any recent info on this.
I think it should be possible as a lot of sites offer easy fb apps to businesses.
Any help would be welcome!
EDIT: Could this last piece of info in the Facebook link above be used to do this? I don't quite get it yet.
In addition, your app will also receive a string parameter called app_data as part of signed_request if an app_data parameter was set in the original query string in the URL your tab is loaded on. It could look like this: "https://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here". You can use that to customize the content you render if you control the generation of the link.
Well... Preventing users from adding your application to their page is impossible. You can't prevent that.
What you will be able to do is to detect who has added your application and according to that, change the content (or not display it at all). So you'll have to start with a list of "allowed" page_ids to match to the accounts you want.
Your application will receive a signed_request each time a user arrives at your application (within a page). Inside that signed_request is information not only on the user but also on the page that the application is on (provided it is a page tab app).
Once you have obtained the signed_request, it will hold a page key which contains:
A JSON object containing the page id string, the liked boolean (set to
true if the user has liked the page, false if not) and the admin
boolean (set to true if the user is an admin of the page, false if
they're not). This field is only present if your app is being loaded
within a Page Tab.
So you'll be able to access the page_id from within this variable and make a decision on the type of content you want to be displayed.
Ok, after running some tests I found out that when you add a URL as 'next' parameter to the install URL Facebook will send the admin(user) back to this URL while adding an array to the request containing all the page Id's the app was installed to.
Like this: YOUR_CALLBACK_URL?tabs_added[ID]=1
Proved to be quite easy in the end

http://www.facebook.com/sharer.php?u= content not refreshing with page updates

I have noticed this numerous times, and have yet to find a fix; when using the share link (http://www.facebook.com/sharer.php?u=MyUrl&t=titleInfo), it pulls in the image, page title, and description from MyUrl just fine. However, it seems to ignore &t, and just uses the page title regardless. That is not the big issue though.
The problem is, if I totally change my page title and opening text, the share link won't update. It seems locked on whatever the page had on it the first time I tested the share link. Is there a way to make it refresh?
In my instance, I was updating some site pages from last years contest edition. Before I got the main page updated, I was working on the FB share link on a different page. I clicked it to test if it worked with the new graphic, and it did, but it of course pulled up the 2012 page content.
Then I went and updated all of the page content to make it for this contest (same URL) and now no matter who tests it, it is still pulling up last year's info (page title and description). It is as if FB has locked that info in and no matter who shares my link, it always pulls up the old text.
I have seen this before with YouTube links. Someone has shared one, I go in later and change the title, and no matter who shares it it never updates because that first initial share text seems permanently locked in FB.
Does anyone know how I can make it refresh, without having to make a whole new URL from last year?
actually facebook gets your page information at the time of posting and save it in their database. so next time it fetches that url and information from their database not from your page.
you may have to share that page again to make new entry in database of the facebook. but old one will remain there.
You can force Facebook to clear their cache by using their debugger. Enter the URL in question at https://developers.facebook.com/tools/debug. You need to do this for each page you are working on.
There are also some rules about not changing the info they have if there are more that (50)? likes.

How to send a Facebook page as url using the Facebook send button?

I will try to explain a bit the context for my problem.
Context:
A while ago I started working on Facebook application. One of the requirements is to be included in a Facebook page as a tab. This application will contain on a page a send button in order to be able to make it more engaging with specific people, users of the application would choose on their own. The reason behind this is because the Facebook page containing the application is related to alcohol, and "liking" the application will get more audition and potential children. Another reason for using send button rather then other similar options from Facebook (like send dialog etc.) is because in Facebook documentation was stated that send button works on mobile devices and other options don't.
Problem:
My problem is related to the send button. What I need is to be able to completely configure the send button: url, image, title, description. I have research the open graph tags in order to be able to do this. Everything works fine if the page I want to be sent with the message is a website OUTSIDE Facebook. Once I started to use the url of a Facebook page (let's call it www.facebook.com/mycustompage), then the crawler takes the images, title, description from facebook.com ignoring the actual page and the produced message is not what I want.
I have searched a lot to better understand this limitation and could not find anything relevant.
The only article I could find as a potential solution was (and even this I had trouble finding):
Send button returning error codes, like button works fine
The above discussion is a workaround which I have already put in place but is not 100% what I want. The described workaround is about putting in the send button:
<div class="fb-send" data-href="http://www.mycustomdomain.com/og"></div>
a page that sniffs the user agent. In case the user agent is Facebook crawler to serve an html empty page just with the open graph tags, otherwise redirect to the desired URL - which in our case is the facebook page www.facebook.com/mycustompage.
The message produced contains:
the title which is a link to www.mycustomdomain.com/og which when
clicked opens a page in a new tab with the address
www.facebook.com/mycustompage - this is relatively ok
under the title I have a "sub-title" readonly text containing the domain of the link: www.mycustomdomain.com - THIS IS NOT OK since I don't want to share where I have hosted the application.
the image and the desired description - this is ok.
Conclusion:
What I want to know if there is a better way to do this rather than this workaround.
If not I would like to know how I can hide for the produced message the "sub-title" so that the hosted domain is not visible.

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

Grabbing data from an iframe embedded Facebook application

Using an iFrame, someone on my website can access their Facebook account, display a list of their photo albums, and then display photos from selected albums.
At the moment, when the user clicks a photo, I display a dialog box that shows the photo's path.
All of the above works perfectly.
My next step is to pass the photo's path info back to my web page, but I'm not sure how to do that because the object, to which I want to pass the data, is outside of the iFrame and therefore unknown to Facebook. I tried going top-down by referencing it through the DOM that contains the iFrame on my website...
parent.client.document.getElementById("FBPhoto").setValue(photoReference);
...but that didn't work.
Passing the argument to a PHP script, on my site, won't work because I don't want to fresh the page on my site (since that would cause the user to lose data).
From what you've provided it looks like your JS might be wrong.
Doing something like this might get you the value you need:
var photoReference = window.frames["iframe-name"].document.getElementById("FBPhoto");
Then you need to assign it to something:
MyObject.setValue(photoReference);
Note: window.frames["iframe-name"].document.getElementById("FBPhoto") will return the DOM element called #FBPhoto and will therefore be a big chunk of HTML. Your setValue() method might not be expecting that.
I suggest you try running your script in Firefox with Firebug installed, which will allow you to dump the value of photoReference to the console to see what you're getting back.
Doy... I realized that since the Facebook connection was running in a dedicated iFrame, it wouldn't be a problem to re-direct that frame because there was no reason to leave it open anyhow.
For anyone interested, here's what I did...
The PHP (inside of index.php) displays the album photos.
The PHP also surrounds each img frame with href tags.
The link points to a PHP file (on my website) and includes an argument with the location of the large version of the photo (since my app is displaying thumbnails). Something like: "< a href="pathToMySite/get-photo.php?photopath=facebook's path ">
When the user clicks on the desired photo, its respective link calls get-photo.php (on my site) and passes the path for the photo.
get-photo.php then inserts a reference to my website's main JS file into the document head, and inserts a script into the body of the HTML document.
The script calls a JS fetch-photo function, and passes the path argument that it received from the embedded iFrame that was running the Facebook app.
The JS function closes the iFrame (since I'm done with Facebook at that point) and grabs the photo from Facebook.