public string photosHTTPRequest(string merchantName, string latValue, string lonValue) { GoogleAPIClient gpObject = new GoogleAPIClient(); // Make a place search API call to place_id string basePlaceURL = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"; string APIkey = "AIzaSyADWTa8YQtzzCzWLH1dZv17Ad8gCRNcDQ0"; string requestPlaceURL = basePlaceURL + "inputtype=textquery&key=" + APIkey + "&input=" + merchantName + "&locationbias=circle:1600@" + latValue + "," + lonValue; Tuple <string, string> gpPlaceAuthCall = gpObject.DoMutualAuthCall(requestPlaceURL, "GET", "Google Places API Test", ""); string gpPlaceStatus = gpPlaceAuthCall.Item1; string gpPlaceResponse = gpPlaceAuthCall.Item2; var gpPlaceResponseJSON = JSON.Parse(gpPlaceResponse); string place_id = "place_id=" + gpPlaceResponseJSON["candidates"][0]["place_id"]; Debug.Log("Place search response: " + gpPlaceResponse); string baseDetailURL = "https://maps.googleapis.com/maps/api/place/details/json?"; string requestDetailURL = baseDetailURL + place_id + "&fields=photos&key=" + APIkey; Tuple <string, string> gpDetailAuthCall = gpObject.DoMutualAuthCall(requestDetailURL, "GET", "Google Places API Test", ""); string gpDetailStatus = gpDetailAuthCall.Item1; string gpDetailResponse = gpDetailAuthCall.Item2; var gpDetailResponseJSON = JSON.Parse(gpDetailResponse); // Get photo info string width = gpDetailResponseJSON["result"]["photos"][0]["width"]; string height = gpDetailResponseJSON["result"]["photos"][0]["height"]; string photo_reference = gpDetailResponseJSON["result"]["photos"][0]["photo_reference"]; string photoUrl = "https://maps.googleapis.com/maps/api/place/photo?" + "maxwidth=" + width + "&photo_reference=" + photo_reference + "&key=" + APIkey; return(photoUrl); }
public void UpdateReviews(string merchantName, string latValue, string lonValue) { Debug.Log("enter update reviews!!!!!!!!!!!!!!!!!!!"); Text text = gameObject.GetComponent <Text>(); var text_height = gameObject.GetComponent <RectTransform>(); GoogleAPIClient gpObject = new GoogleAPIClient(); string basePlaceURL = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"; string APIkey = "AIzaSyADWTa8YQtzzCzWLH1dZv17Ad8gCRNcDQ0"; string requestPlaceURL = basePlaceURL + "inputtype=textquery&key=" + APIkey + "&input=" + merchantName + "&locationbias=circle:1600@" + latValue + "," + lonValue; Tuple <string, string> gpPlaceAuthCall = gpObject.DoMutualAuthCall(requestPlaceURL, "GET", "Google Places API Test", ""); string gpPlaceStatus = gpPlaceAuthCall.Item1; string gpPlaceResponse = gpPlaceAuthCall.Item2; if (gpPlaceStatus != "OK") { Debug.Log("Invalid place status: " + gpPlaceStatus); return; } var gpPlaceResponseJSON = JSON.Parse(gpPlaceResponse); if (gpPlaceResponseJSON["candidates"].AsArray.Count == 0) { Debug.Log("Find place returned no results."); return; } string place_id = "place_id=" + gpPlaceResponseJSON["candidates"][0]["place_id"]; Debug.Log("Place search response: " + gpPlaceResponse); //Detail API request string baseDetailURL = "https://maps.googleapis.com/maps/api/place/details/json?"; //string place_id = "place_id=ChIJXZiBbDDsa4cRobxsl8GF2Is"; string requestDetailURL = baseDetailURL + place_id + "&fields=reviews&key=" + APIkey; Tuple <string, string> gpDetailAuthCall = gpObject.DoMutualAuthCall(requestDetailURL, "GET", "Google Places API Test", ""); string gpDetailStatus = gpDetailAuthCall.Item1; string gpDetailResponse = gpDetailAuthCall.Item2; if (gpDetailStatus != "OK") { Debug.Log("Invalid detail status: " + gpDetailStatus); return; } var gpDetailResponseJSON = JSON.Parse(gpDetailResponse); Debug.Log(gpDetailResponseJSON.ToString()); string user, rating, timestamp, review; string display = ""; for (int i = 0; i < 5; i++) { user = "******" + gpDetailResponseJSON["result"]["reviews"][i]["author_name"] + "</b>"; rating = gpDetailResponseJSON["result"]["reviews"][i]["rating"]; timestamp = "<i>" + gpDetailResponseJSON["result"]["reviews"][i]["relative_time_description"] + "</i>"; review = gpDetailResponseJSON["result"]["reviews"][i]["text"]; display += "―――――――――――――\n―――――――――――――\n" + user + "\n" + stars_graphic(float.Parse(rating)) + "\n<i> Posted </i>" + timestamp + "\n―――――――――――――" + "\n" + review + "\n"; } text.text = display; float pref_height = text.preferredHeight; text_height.sizeDelta = new Vector2(275, pref_height); text_height.localPosition = new Vector2(0, -1 * text_height.sizeDelta.y / 2); //text_height.pos /* * string user1 = "<b>" + gpDetailResponseJSON["result"]["reviews"][0]["author_name"] + "</b>"; * string rating1 = gpDetailResponseJSON["result"]["reviews"][0]["rating"]; * string timestamp = "<i>" + gpDetailResponseJSON["result"]["reviews"][0]["relative_time_description"] + "</i>"; * string review1 = gpDetailResponseJSON["result"]["reviews"][0]["text"]; * * text.text = user1 + "\n" + rating1 + " out of 5 stars" + "\n<i> Posted </i>" + timestamp + "\n―――――――――――――――――――" + "\n" + review1; */ }
// Update ratings public void UpdateRating(string merchantName, string latValue, string lonValue) { /* * Additions by Luke Joyce * 6/27/2020 */ // Make Google Places API call // Maps API key: AIzaSyADWTa8YQtzzCzWLH1dZv17Ad8gCRNcDQ0 Text text = gameObject.GetComponent <Text>(); GoogleAPIClient gpObject = new GoogleAPIClient(); // Make a place search API call to place_id string basePlaceURL = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"; string APIkey = "AIzaSyADWTa8YQtzzCzWLH1dZv17Ad8gCRNcDQ0"; string requestPlaceURL = basePlaceURL + "inputtype=textquery&key=" + APIkey + "&input=" + merchantName + "&locationbias=circle:1600@" + latValue + "," + lonValue; Tuple <string, string> gpPlaceAuthCall = gpObject.DoMutualAuthCall(requestPlaceURL, "GET", "Google Places API Test", ""); string gpPlaceStatus = gpPlaceAuthCall.Item1; string gpPlaceResponse = gpPlaceAuthCall.Item2; if (gpPlaceStatus != "OK") { Debug.Log("Invalid place status: " + gpPlaceStatus); return; } var gpPlaceResponseJSON = JSON.Parse(gpPlaceResponse); if (gpPlaceResponseJSON["candidates"].AsArray.Count == 0) { Debug.Log("Find place returned no results."); return; } string place_id = "place_id=" + gpPlaceResponseJSON["candidates"][0]["place_id"]; Debug.Log("Place search response: " + gpPlaceResponse); // Make a place detail API call string baseDetailURL = "https://maps.googleapis.com/maps/api/place/details/json?"; //string place_id = "place_id=ChIJXZiBbDDsa4cRobxsl8GF2Is"; string requestDetailURL = baseDetailURL + place_id + "&fields=name,rating,reviews,formatted_phone_number,formatted_address,business_status,price_level&key=" + APIkey; Tuple <string, string> gpDetailAuthCall = gpObject.DoMutualAuthCall(requestDetailURL, "GET", "Google Places API Test", ""); string gpDetailStatus = gpDetailAuthCall.Item1; string gpDetailResponse = gpDetailAuthCall.Item2; if (gpDetailStatus != "OK") { Debug.Log("Invalid detail status: " + gpDetailStatus); return; } var gpDetailResponseJSON = JSON.Parse(gpDetailResponse); // Change text string rating = gpDetailResponseJSON["result"]["rating"].Value; string phone_number = gpDetailResponseJSON["result"]["formatted_phone_number"]; string address = gpDetailResponseJSON["result"]["formatted_address"]; string price_level = gpDetailResponseJSON["result"]["price_level"]; string business_status = gpDetailResponseJSON["result"]["business_status"]; //string desiredText = gpDetailResponseJSON.ToString(); text.text = "Rating: " + rating + "\nPhone number: " + phone_number + "\nAddress: " + address + "\nPrice level: " + price_level + "\nBusiness status: " + business_status; }