{"id":21,"date":"2023-11-17T19:48:17","date_gmt":"2023-11-17T19:48:17","guid":{"rendered":"https:\/\/xengage.com\/insights\/?p=21"},"modified":"2023-11-17T19:48:18","modified_gmt":"2023-11-17T19:48:18","slug":"fetching-google-reviews-results-with-php","status":"publish","type":"post","link":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/","title":{"rendered":"Fetching Google Reviews Results with PHP"},"content":{"rendered":"\n<p>To fetch Google Reviews using PHP, you&#8217;ll need to make use of the Google Places API, specifically the Place Details request. This involves sending an HTTP request to Google&#8217;s API endpoint and parsing the JSON response to extract the reviews. Here&#8217;s a PHP code snippet that demonstrates this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\/\/ Replace with your actual API key and Place ID\r\n$apiKey = 'YOUR_API_KEY';\r\n$placeId = 'YOUR_PLACE_ID';\r\n\r\n\/\/ URL for the Google Places API request\r\n$url = \"https:\/\/maps.googleapis.com\/maps\/api\/place\/details\/json?placeid=$placeId&amp;fields=reviews&amp;key=$apiKey\";\r\n\r\n\/\/ Fetch data from the API\r\n$response = file_get_contents($url);\r\n\r\nif ($response !== false) {\r\n    $data = json_decode($response, true);\r\n\r\n    if ($data&#91;'status'] === 'OK' &amp;&amp; isset($data&#91;'result']&#91;'reviews'])) {\r\n        $reviews = $data&#91;'result']&#91;'reviews'];\r\n\r\n        \/\/ Process reviews if needed or store them in an array\r\n        $formattedReviews = &#91;];\r\n        foreach ($reviews as $review) {\r\n            $formattedReview = &#91;\r\n                'author_name' => $review&#91;'author_name'],\r\n                'rating' => $review&#91;'rating'],\r\n                'text' => $review&#91;'text'],\r\n            ];\r\n            $formattedReviews&#91;] = $formattedReview;\r\n        }\r\n\r\n        \/\/ Store reviews in an array called 'reviews'\r\n        $reviews = $formattedReviews;\r\n\r\n        \/\/ Print or process the fetched reviews\r\n        var_dump($reviews); \/\/ This will display the reviews as an array\r\n    } else {\r\n        echo 'No reviews found.';\r\n    }\r\n} else {\r\n    echo 'Failed to fetch reviews.';\r\n}\r\n?>\r\n<\/code><\/pre>\n\n\n\n<p>Replace <code>'YOUR_API_KEY'<\/code> with your actual Google API key and <code>'YOUR_PLACE_ID'<\/code> with the Place ID of the desired location.<\/p>\n\n\n\n<p>This code uses <code>file_get_contents()<\/code> to fetch data from the Google Places API endpoint. It then decodes the JSON response and extracts the reviews, storing them in an array called <code>$reviews<\/code>. You can further process or manipulate the reviews as needed within the PHP code. The <code>var_dump($reviews)<\/code> line is for demonstration purposes to display the fetched reviews in the PHP script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To fetch Google Reviews using PHP, you&#8217;ll need to make use of the Google Places API, specifically the Place Details request. This involves sending an HTTP request to Google&#8217;s API endpoint and parsing the JSON response to extract the reviews. Here&#8217;s a PHP code snippet that demonstrates this: Replace &#8216;YOUR_API_KEY&#8217; with your actual Google API [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[4,7],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-coding","tag-google","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Fetching Google Reviews Results with PHP - Xengage Insights<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fetching Google Reviews Results with PHP - Xengage Insights\" \/>\n<meta property=\"og:description\" content=\"To fetch Google Reviews using PHP, you&#8217;ll need to make use of the Google Places API, specifically the Place Details request. This involves sending an HTTP request to Google&#8217;s API endpoint and parsing the JSON response to extract the reviews. Here&#8217;s a PHP code snippet that demonstrates this: Replace &#039;YOUR_API_KEY&#039; with your actual Google API [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Xengage Insights\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-17T19:48:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-17T19:48:18+00:00\" \/>\n<meta name=\"author\" content=\"Xengage\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Xengage\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\"},\"author\":{\"name\":\"Xengage\",\"@id\":\"https:\/\/xengage.com\/insights\/#\/schema\/person\/d2ac92e40345bccdc6af9fd6ec7d0aca\"},\"headline\":\"Fetching Google Reviews Results with PHP\",\"datePublished\":\"2023-11-17T19:48:17+00:00\",\"dateModified\":\"2023-11-17T19:48:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\"},\"wordCount\":127,\"publisher\":{\"@id\":\"https:\/\/xengage.com\/insights\/#organization\"},\"keywords\":[\"Google\",\"PHP\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\",\"url\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\",\"name\":\"Fetching Google Reviews Results with PHP - Xengage Insights\",\"isPartOf\":{\"@id\":\"https:\/\/xengage.com\/insights\/#website\"},\"datePublished\":\"2023-11-17T19:48:17+00:00\",\"dateModified\":\"2023-11-17T19:48:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/xengage.com\/insights\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fetching Google Reviews Results with PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/xengage.com\/insights\/#website\",\"url\":\"https:\/\/xengage.com\/insights\/\",\"name\":\"Xengage Insights\",\"description\":\"Digital Marketing &amp; Technology Blog\",\"publisher\":{\"@id\":\"https:\/\/xengage.com\/insights\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/xengage.com\/insights\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/xengage.com\/insights\/#organization\",\"name\":\"Xengage Insights\",\"url\":\"https:\/\/xengage.com\/insights\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/xengage.com\/insights\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/xengage.com\/insights\/cms\/wp-content\/uploads\/2024\/01\/cropped-xengage-logo.jpg\",\"contentUrl\":\"https:\/\/xengage.com\/insights\/cms\/wp-content\/uploads\/2024\/01\/cropped-xengage-logo.jpg\",\"width\":512,\"height\":512,\"caption\":\"Xengage Insights\"},\"image\":{\"@id\":\"https:\/\/xengage.com\/insights\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/xengage.com\/insights\/#\/schema\/person\/d2ac92e40345bccdc6af9fd6ec7d0aca\",\"name\":\"Xengage\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/xengage.com\/insights\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/acaa5835a18f0598852d95ace0504d2d1e12e6eb408fec04921d24eba14c2057?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/acaa5835a18f0598852d95ace0504d2d1e12e6eb408fec04921d24eba14c2057?s=96&d=mm&r=g\",\"caption\":\"Xengage\"},\"sameAs\":[\"https:\/\/xengage.com\/insights\/cms\"],\"url\":\"https:\/\/xengage.com\/insights\/author\/xengage\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fetching Google Reviews Results with PHP - Xengage Insights","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/","og_locale":"en_US","og_type":"article","og_title":"Fetching Google Reviews Results with PHP - Xengage Insights","og_description":"To fetch Google Reviews using PHP, you&#8217;ll need to make use of the Google Places API, specifically the Place Details request. This involves sending an HTTP request to Google&#8217;s API endpoint and parsing the JSON response to extract the reviews. Here&#8217;s a PHP code snippet that demonstrates this: Replace 'YOUR_API_KEY' with your actual Google API [&hellip;]","og_url":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/","og_site_name":"Xengage Insights","article_published_time":"2023-11-17T19:48:17+00:00","article_modified_time":"2023-11-17T19:48:18+00:00","author":"Xengage","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Xengage","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/#article","isPartOf":{"@id":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/"},"author":{"name":"Xengage","@id":"https:\/\/xengage.com\/insights\/#\/schema\/person\/d2ac92e40345bccdc6af9fd6ec7d0aca"},"headline":"Fetching Google Reviews Results with PHP","datePublished":"2023-11-17T19:48:17+00:00","dateModified":"2023-11-17T19:48:18+00:00","mainEntityOfPage":{"@id":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/"},"wordCount":127,"publisher":{"@id":"https:\/\/xengage.com\/insights\/#organization"},"keywords":["Google","PHP"],"articleSection":["Coding"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/","url":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/","name":"Fetching Google Reviews Results with PHP - Xengage Insights","isPartOf":{"@id":"https:\/\/xengage.com\/insights\/#website"},"datePublished":"2023-11-17T19:48:17+00:00","dateModified":"2023-11-17T19:48:18+00:00","breadcrumb":{"@id":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/xengage.com\/insights\/fetching-google-reviews-results-with-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/xengage.com\/insights\/"},{"@type":"ListItem","position":2,"name":"Fetching Google Reviews Results with PHP"}]},{"@type":"WebSite","@id":"https:\/\/xengage.com\/insights\/#website","url":"https:\/\/xengage.com\/insights\/","name":"Xengage Insights","description":"Digital Marketing &amp; Technology Blog","publisher":{"@id":"https:\/\/xengage.com\/insights\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/xengage.com\/insights\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/xengage.com\/insights\/#organization","name":"Xengage Insights","url":"https:\/\/xengage.com\/insights\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/xengage.com\/insights\/#\/schema\/logo\/image\/","url":"https:\/\/xengage.com\/insights\/cms\/wp-content\/uploads\/2024\/01\/cropped-xengage-logo.jpg","contentUrl":"https:\/\/xengage.com\/insights\/cms\/wp-content\/uploads\/2024\/01\/cropped-xengage-logo.jpg","width":512,"height":512,"caption":"Xengage Insights"},"image":{"@id":"https:\/\/xengage.com\/insights\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/xengage.com\/insights\/#\/schema\/person\/d2ac92e40345bccdc6af9fd6ec7d0aca","name":"Xengage","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/xengage.com\/insights\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/acaa5835a18f0598852d95ace0504d2d1e12e6eb408fec04921d24eba14c2057?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/acaa5835a18f0598852d95ace0504d2d1e12e6eb408fec04921d24eba14c2057?s=96&d=mm&r=g","caption":"Xengage"},"sameAs":["https:\/\/xengage.com\/insights\/cms"],"url":"https:\/\/xengage.com\/insights\/author\/xengage\/"}]}},"_links":{"self":[{"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":2,"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/posts\/21\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xengage.com\/insights\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}