Google API密钥限制 - HTTP引用者
我将我的Azure网站url xxxx.scm.azurewebsites.net放在那里,但不起作用(Google Places API Web Service停止工作)。
localhost:44300也不起作用。
我必须将密钥限制设置为“无”,然后Google Places API Web Service才能正常工作。
我做错了什么?
Google API密钥限制 - HTTP引用者
我将我的Azure网站url xxxx.scm.azurewebsites.net放在那里,但不起作用(Google Places API Web Service停止工作)。
localhost:44300也不起作用。
我必须将密钥限制设置为“无”,然后Google Places API Web Service才能正常工作。
我做错了什么?
Web Service应该在后端服务器上执行,因此对于Web服务的正确限制是IP限制。
HTTP referer限制用于客户端服务(如Google Maps JavaScript API),它无法与Web服务一起使用。
为了在Google Maps API中接受本地主机和HTTP请求(HTTP引用),请按照Google Maps API在javascript控制台中打印的说明进行操作(它会告诉您确切的操作步骤):
Google Maps API错误:RefererNotAllowedMapErrorhttps://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error
需要授权的站点URL:http://localhost:3000/en
“需要授权的站点URL”一行指示您必须在“接受这些HTTP引用(网站)的请求”中设置哪个值
例如,对于Ruby on Rails应用程序,它是:
http://localhost:3000/en
但是你可以更好地使用星号作为通配符:
*localhost:3000/*
将值设置为localhost:3000/*是不起作用的!
我在Google Cloud Platform的VM上,使用帐户account_1@gmail.com,在子域名www.mydomain.com上部署了Wordpress click-to-deploy。
此外,我还在Firebase Hosting上使用帐户account_2@gmail.com,在子域名app.mydomain.com上拥有一个Web应用程序。
用户登录WordPress后,PHP后端通过POST API Rest在Firebase Auth中创建用户,接收响应,并允许或禁止访问应用程序。
为防止Firebase API被恶意使用(该API在应用程序中可见),我启用了HTTP限制。
在这些限制中,我放置了:
*.mydomain.com/*
和mydomain.com/*
)。*.firebaseapp.com/*
和firebaseapp.com/*
)。*.googleapis.com/*
和googleapis.com/*
)。我以为这就足够了,但是WordPress停止了发送信息。
解决方案:
我在Linux终端中使用“ping”,指向我的WordPress网站(ping www.mydomain.com
),得到以下结果:
64 bytes from xx.yy.zzz.aa.bc.googleusercontent.com (xx.yy.zzz.aa): icmp_seq=70 ttl=56 time=199 ms
我复制了根域名 (googleusercontent.com
) 并将其添加到 API 限制中,然后它就可以工作了。
(如果我的英语有错误,请见谅。)