为了账号安全,请及时绑定邮箱和手机立即绑定

从 localhost 调用 Google API

从 localhost 调用 Google API

PHP
慕沐林林 2022-06-11 09:56:34
我正在尝试从我的 localhost Docker 容器中调用 Google CSE Api。显然,正因为如此,这不起作用。我已定义CURLOPT_SSL_VERIFYPEER为 false 以防止 SSL 证书验证,但没有成功。如果有人对此有任何想法,我们将不胜感激。我的代码:// Create the google api client$googleClient = new Google_Client();// Set the google developer api key$googleClient->setApplicationName('GoogleApi_Search');$googleClient->setDeveloperKey(self::GOOGLE_SEARCH_API_KEY);// for development purposes$guzzleConfig = [    'curl'    => [CURLOPT_SSL_VERIFYPEER => false],    'headers' => ['Referer' => 'localhost:8080'],];$guzzleClient = new Client($guzzleConfig);$googleClient->setHttpClient($guzzleClient);// The google custom search service client$this->googleService = new Google_Service_Customsearch($googleClient);// Define the search parameters$this->searchParams = [    'cx'    => self::GOOGLE_SEARCH_ENGINE_ID,   // Custom search engine identifier    'gl'    => 'en',                            // Location of results    'lr'    => 'lang_en',                       // Language of results    'num'   => 10,                              // Number of results (max. 10)    'start' => 0,                               // The current index (max. 10)];
查看完整描述

1 回答

?
慕村9548890

TA贡献1884条经验 获得超4个赞

start我通过将参数设置为1而不是0解决了我的问题。显然,将其设置为在服务器端0触发致命错误,导致错误400 Invalid Value并且没有其他信息。

奇怪但有效。


查看完整回答
反对 回复 2022-06-11
  • 1 回答
  • 0 关注
  • 156 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号