开发者

Facebook app: Random quotes not refreshing on each page load

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开发者_Go百科 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:

  1. 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).
  2. Accessing this dynamic image in a browser gives you a different random quote each time you refresh.
  3. On the Facebook profile box or tab, simply link this image.
  4. However, Facebook caches the image the first time it's loaded, so it never updates!
  5. 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!
  6. 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.
  7. 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.
  8. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜