Google Places API excluding permanently closed locations? - r

I have been using Google Places Search API to look for permanently closed locations. As it turns out google filters them out from the query results.
For example : Cumberland River Hospital shows up as permanently closed on the google maps
https://www.google.com/search?rlz=1C1GCEV_enUS859US859&ei=JpzVXdXxDq2d_Qams6KwBg&q=Cumberland+River+Hospital&oq=Cumberland+River+Hospital&gs_l=psy-ab.3..0l6j0i22i30l4.3132.3757..4013...0.0..0.229.882.0j4j1......0....1..gws-wiz.3587Ce7Fh7c&ved=0ahUKEwjVnJrvyvnlAhWtTt8KHaaZCGYQ4dUDCAs&uact=5
Now as a test, I try to search for all hospitals in the same coordinates using googleway package as follows :
library('googleway')
hosps <- google_places(
location = c(36.544690,-85.500820),
keyword = 'hospital',
key = api,
rankby = 'distance',
simplify = TRUE)
and it skips out the "Cumberland River Hospital" from the search results.
However, when I try to search specifically for "Cumberland River Hospital" in the same coordinates Google Places Search API returns information for that particular hospital that includes a flag "permanently_closed" = TRUE indicating that this place is permanently closed.
library('googleway')
pc_hosp <- google_places(
location = c(36.544690,-85.500820),
keyword = "cumberland river hospital",
key = api,
rankby = 'distance',
simplify = TRUE)
Why does Google Places API skip permanently closed location from the regular search results ? Is there a way to include the permanently closed locations along with the regular establishments using Google Places Search API ?

Related

Build Segment with RSiteCatalyst for Many Urls

I have a list of 100 urls that I need to pull analytics for. Suppose that the list is as follows:
allUrls <- c("google.com", "facebook.com", "instagram.com", "netflix.com")
I want to be able to pass a segment to adobe in RSiteCatalyst where the url is equal to one of the list of 100 urls. I've been able to build segments like the following
library(RSiteCatalyst)
rules <- data.frame(name = c("google", "facebook" ,"instagram", "netflix"),
element = c("url", "url", "url", "url"),
operator = c("equals", "equals", "equals", "equals"),
value = allUrls)
adobeSegment <- list(container = list(type = unbox("hits"),
rules = rules))
but I dont know how to specify that I want these to be OR rules, not AND. I looked into the BuildClassificationValueSegment function but I can't seem to make sense of the inputs, nor could I find any good examples of how it works.
I'm just hoping for an output of a df that'd look something like this:
url visits
google 1000
facebook 8000
instagram 3276
netflix 4675

Radlibrary not returning all ads from Meta/Facebook Ad Library

I am trying to get all ads from different political pages on Facebook using the Radlibrary package in R -- which I have done a hundred times before with no problem at all. Now I experience that some ads are not returned -- there`s no system in which ads are not returned: for one party it is just a few ads in april 2022, for another it's all ads after 1/1/2021 -- but the thing in common is that I get some of the ads.
The problem is similar to the one described here: https://github.com/facebookresearch/Radlibrary/issues/103
Also, I know the ads are available since they are 1) displayed both in the browser version of the Ad Library but also if I download them as a .csv file from facebook.com/ads/library and 2) I have managed to get the ads that now are missing in a previous pull a couple of months ago
My code is (which only returns 117 out of 210 ads):
library("Radlibrary")
query_ad <- adlib_build_query(ad_reached_countries = 'DK',
ad_active_status = 'ALL',
search_terms = "NULL",
search_page_ids = "223040066022",
fields = c(
"id",
"ad_creation_time",
"ad_creative_bodies",
"ad_delivery_start_time",
"ad_delivery_stop_time",
"ad_snapshot_url",
"currency",
"page_id",
"page_name",
"publisher_platforms",
"impressions",
"spend"
))
response_ad <- adlib_get_paginated(query_ad, max_gets = 10, token = token)
results_tibble_ad <- as_tibble(response_ad, type = "ad",
censor_access_token = NULL)
This is resolved in the newest release.

Authorization in R API, specifically for League of Legends

I am learning how to use API in R and it is going well for the most part, but I am having trouble getting any data from the league of legends API.
For reference, I used this article as a start (https://www.dataquest.io/blog/r-api-tutorial/) and cop
res <- GET("http://api.open-notify.org/astros.json")
res
This worked just fine and has a 200 status, but I am not interested in that data.
What I want is data about league of legends, so I am trying to use:
base.url <- "https://na1.api.riotgames.com"
path <- "/lol/champion-mastery/v4/champion-masteries/by-summoner/"
API_Key <- read.table("riotkey.txt")
API_KEY <- API_Key$V1
Summoner_ID <- read.table("summonerID.txt")
SUMMONER_ID <- Summoner_ID$V1
path <- paste0(path,SUMMONER_ID)
LoL_API_Test <- GET(base.url, path = path,
add_headers(Authorization = API_KEY))
LoL_API_Test
This is Riot's explanation for the 403 error - Forbidden. "This error indicates that the server understood the request but refuses to authorize it. There is no distinction made between an invalid path or invalid authorization credentials (e.g., an API key)"
I am certain that my API key and summoner ID are correct.
So I assume the issue has to be with how I am requesting the data.
What am I doing wrong?
This particular API expects the API key to be passed in a header called "X-Riot-Token", not "Authorization". Change your call to
LoL_API_Test <- GET(base.url, path = path,
add_headers("X-Riot-Token" = API_KEY))

Supporting Airport codes in geocode & calculate route

Is there any API to get geocode for airport code?
For ex: if I need to calculate time from home(say its Malibu) to LAX(Los Angeles Intl. Airport), Ideally I would follow below steps:
Get my home address geo location(via geocoder)
Get LAX geo location(via geocoder)
Use above as source and destination in "calculateroute".
However when I use "LAX" in geocoder, its gives some place in CHE(Switzerland).
If I append with country(USA), its listing some other place in Georgia.
*https://geocoder.api.here.com/6.2/geocode.json?app_id=MY-APP-ID&app_code=MY-APP-CODEgen=9&searchtext=LAX
https://geocoder.api.here.com/6.2/geocode.json?app_id=MY-APP-ID&app_code=MY-APP-CODEgen=9&searchtext=LAX,USA*
Is there any alternate way to do it OR the only way is for me to maintain a map of IATA airport codes with their geo coordinates and use it directly in calculateroute?
To get the geocode of an Airport:
Use Landmark geocoding: categoryids=4581
categoryids
xs:integer
Limit landmark results to one or more categories. Examples:
Highway exits: 116
Airports: 4581
Tourist attractions: 7999
Example:
http://geocoder.api.here.com/6.2/search.json?categoryids=4581&gen=8&jsonattributes=1&language=en-US&maxresults=20&searchtext=LAX&app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}
Read more at developer.here.com/documentation/geocoder/topics/resource-search.html

Geocoding node-red-node-google. Error "Invalid request. Invalid 'latlng' parameter"

I´m not an expert in node-red and truly appreciate some help on using the node-red-node-google geocoding node.
link to Google Geolocation node-red node
I'm trying to obtain the location address via google Geolocation API from previously obtained coordinates using the node mentioned above (geocode by coordinates option). I take latitude and length via POST from an external application.
How should the latitude and longitude data be fed into the geocode node to get the correct address data? After tens of tests, I always obtain the same error: "Invalid request. Invalid 'latlng' parameter".
What I'm doing is:
Take data generated via POST http://my_public_ip:1880/geo?id={device}&time={time}&lat={lat}&lng={lng}&radius={radius}
The first node of the flow is a node-red Http In node, that implements the htp end-point, gets the info from that callback. Te info is retrieved correctly (see debug output) :
{"id":"18A834","time":"1503231980","lat":"40.xxxxxxxxxxxxxx","lng":"-3.xxxxxxxxxxxxxx","radius":"1651"}
Note: coordinates shadowed by privacy reasons.
If lng and lat values from the HTTP In node are fed into the Google Geocoding node, the message error "Invalid request. Invalid 'latlng' parameter" is received.
I fill the dialog box this way:
Latitude text box: msg.payload.lat
Longitude Text box:msg.payload.lng
I have tried several options inserting the coords function node:
convert the latitude and longitude values to float, keep only the first 7 decimals, convert again to strings ..., and always the same error is received: "Invalid request. Invalid 'latlng' parameter"
The coords function node configuration:
var coords ={};
latitude= parseFloat(msg.payload.lat).toFixed(7);
latitude1 = parseFloat(latitude);
var length = parseFloat(msg.payload.lng).toFixed(7);
var length1= parseFloat(length);
coords.payload = {lat:latitude1, lng:length1};
return coords;
The function output seems to be correct:
{"lat":40.xxxxxxx,"lng":-3.xxxxxxx}
So I expected to fill the text boxes with msg.payload.lat and msg.payload.lng should be ok. Clearly something is wrong ...
Does anybody know which is the correct way to feed longitude and latitude values to the node-red-node-google google-geocoding to get no errors?
Find below node-red used code (remember, also tested different types of variable and also tested with no function at all):
[{"id":"4dadb4d9.246a1c","type":"http in","z":"76138ea1.88752","name":"get_coords_from_post","url":"/geo","method":"get","upload":false,"swaggerDoc":"","x":300,"y":200,"wires":[["4a0b74fb.d10fcc","fb89b080.ef1cf","dac1b7ce.4cc2c8"]]},{"id":"fb89b080.ef1cf","type":"function","z":"76138ea1.88752","name":"coords","func":"var coords ={};\nlatitude= parseFloat(msg.payload.lat).toFixed(7);\nlatitude1 = parseFloat(latitude);\nvar length = parseFloat(msg.payload.lng).toFixed(7);\nvar length1= parseFloat(length);\ncoords.payload = {lat:latitude1, lng:length1};\nreturn coords; \n","outputs":1,"noerr":0,"x":510,"y":200,"wires":[["a24b08cf.22ebf8","dac1b7ce.4cc2c8"]]},{"id":"4a0b74fb.d10fcc","type":"http response","z":"76138ea1.88752","name":"","statusCode":"","headers":{},"x":484,"y":131,"wires":[]},{"id":"dac1b7ce.4cc2c8","type":"debug","z":"76138ea1.88752","name":"","active":true,"console":"false","complete":"false","x":990,"y":480,"wires":[]},{"id":"a24b08cf.22ebf8","type":"google geocoding","z":"76138ea1.88752","name":"find_address_from_coords","geocodeBy":"coordinates","address":"","lat":"msg.payload.lat","lon":"msg.payload.lng","googleAPI":"","bounds":"","language":"es","region":"","components":"","x":740,"y":200,"wires":[["dac1b7ce.4cc2c8"]]}]
You shouldn't be putting msg.payload.lat or msg.payload.lon in the config dialog. If you are passing those values in via a message object you need to leave them blank in the config dialog.
Next, as mentioned in the README.md and the info bar in Node-RED, you need to set the msg.location.lat and msg.location.lon on the incoming message to pass those value to the node.
So basically your function node should look a little bit more like this:
var coords ={};
latitude= parseFloat(msg.payload.lat).toFixed(7);
latitude1 = parseFloat(latitude);
var length = parseFloat(msg.payload.lng).toFixed(7);
var length1= parseFloat(length);
coords.location = {lat:latitude1, lon:length1};
return coords;

Resources