Switch homepage review stat from Facebook to Google
- Replace inc/facebook-stats.php with inc/google-reviews.php: fetches
average star rating + review count from the Places API (New) instead
of Facebook's Graph API, same cache-to-JSON/fallback-on-failure shape
as before.
- index.php: stat card now shows the native star rating ("4.8★ average
rating") instead of a recommend %, sourced from Google. Drops the
Facebook-followers line entirely — Google's API has no equivalent and
showing a stale/static number wasn't worth keeping. "Follow on
Facebook" links elsewhere on the site are untouched.
- config.example.php: swap FB_PAGE_ID/FB_PAGE_ACCESS_TOKEN/
FB_STATS_CACHE_TTL/FB_FALLBACK_* for GOOGLE_PLACE_ID/
GOOGLE_PLACES_API_KEY/GOOGLE_STATS_CACHE_TTL/GOOGLE_FALLBACK_RATING/
GOOGLE_FALLBACK_REVIEW_COUNT (set to the pub's actual 4.8★/71 reviews),
with setup instructions in comments. config.php (gitignored) updated
to match.
- Remove the now-dead .stat-row CSS that only existed for the dropped
followers line; rebuild styles.css.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2145094e55
commit
5bed636cca
6 files changed
+117
-150
No files matched your search
+27
-26
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Site config template — tracked in git, safe to commit (no real secret
|
||||
* here). Copy this file to config.php (gitignored) and fill in your own
|
||||
* FB_PAGE_ACCESS_TOKEN there.
|
||||
* GOOGLE_PLACES_API_KEY there.
|
||||
*/
|
||||
|
||||
// Base URL the site is currently reachable at. Used for social sharing
|
||||
@@ -11,33 +11,34 @@
|
||||
// this to the permanent domain once the site moves there.
|
||||
define('SITE_URL', 'https://theoldfitz.daviddyer.me');
|
||||
|
||||
// The Old Fitz's Facebook Page ID (from the facebook.com/profile.php?id=... links already on the site).
|
||||
define('FB_PAGE_ID', '100086635646712');
|
||||
// The Old Fitz's Google Place ID — identifies the business for the
|
||||
// Places API. Look it up with Google's Place ID Finder:
|
||||
// https://developers.google.com/maps/documentation/places/web-service/place-id
|
||||
// (search "The Old Fitz Public House, Marion, IN" and copy the ID shown).
|
||||
define('GOOGLE_PLACE_ID', '');
|
||||
|
||||
// Paste a Page Access Token here to make the homepage stats live.
|
||||
// Until this is filled in, the site quietly uses the fallback numbers below.
|
||||
// API key for the Places API (New), used to fetch the live star rating
|
||||
// and review count for the homepage stat card. Until this is filled in,
|
||||
// the site quietly uses the fallback numbers below.
|
||||
//
|
||||
// To generate one:
|
||||
// 1. Go to https://developers.facebook.com/apps and create an app
|
||||
// (type: "Business"), logged in as an admin of The Old Fitz Page.
|
||||
// 2. In Graph API Explorer (developers.facebook.com/tools/explorer),
|
||||
// pick that app, select "Page Access Token" for The Old Fitz,
|
||||
// requesting the pages_read_engagement permission.
|
||||
// 3. Use the "Access Token Debugger" (developers.facebook.com/tools/debug/accesstoken)
|
||||
// to extend it to a long-lived token (~60 days). Long-lived Page
|
||||
// tokens generally don't expire on their own with regular use, but
|
||||
// Meta can still invalidate one (password change, permission
|
||||
// changes, app review) — if that happens, this just falls back to
|
||||
// the numbers below instead of breaking the page.
|
||||
define('FB_PAGE_ACCESS_TOKEN', '');
|
||||
// 1. Go to https://console.cloud.google.com, create (or pick) a
|
||||
// project, and enable "Places API (New)" under APIs & Services.
|
||||
// 2. Enable billing on the project — Google requires a card on file,
|
||||
// but the free monthly credit comfortably covers a rating/review
|
||||
// lookup cached for hours at a time on a low-traffic site like
|
||||
// this one.
|
||||
// 3. Create an API key (APIs & Services → Credentials) and restrict
|
||||
// it to "Places API (New)" only.
|
||||
define('GOOGLE_PLACES_API_KEY', '');
|
||||
|
||||
// How often to re-fetch from Facebook, in seconds. 6 hours is plenty for
|
||||
// numbers that move a few times a month.
|
||||
define('FB_STATS_CACHE_TTL', 6 * 60 * 60);
|
||||
// How often to re-fetch from Google, in seconds. 6 hours is plenty for
|
||||
// a number that moves a few times a month, and stays well inside
|
||||
// Google's caching allowance for Place Details data.
|
||||
define('GOOGLE_STATS_CACHE_TTL', 6 * 60 * 60);
|
||||
|
||||
// Fallback numbers — used whenever there's no token yet, or the Facebook
|
||||
// API call fails for any reason. Update these by hand if you're not
|
||||
// using the live token.
|
||||
define('FB_FALLBACK_RECOMMEND_PCT', 92);
|
||||
define('FB_FALLBACK_REVIEW_COUNT', 11);
|
||||
define('FB_FALLBACK_FOLLOWERS', 2600);
|
||||
// Fallback numbers — used whenever there's no API key/Place ID yet, or
|
||||
// the Google API call fails for any reason. Update these by hand if
|
||||
// you're not using the live lookup.
|
||||
define('GOOGLE_FALLBACK_RATING', 4.8);
|
||||
define('GOOGLE_FALLBACK_REVIEW_COUNT', 71);
|
||||
Reference in new issue
Block a user