Answer the question
In order to leave comments, you need to log in
How to make Google_Service_YouTube work in yii2?
Good afternoon.
I install the latest version of yii2, Google extensions using:
composer require google/apiclient:^2.0 ( https://github.com/google/google-api-php-client#do...
while it swears at guzzle http. I delete version 1.4.2, after that in composer.json
//
"guzzlehttp/psr7": "1.2.3",
"google/apiclient": "2.0",
"guzzlehttp/guzzle": "6.0"
//
$ids = [];
$ids[] = 'IxjydzXg6cs';
$api_key = Yii::$app->params['youtube_api_key_1'];
$client = new Google_Client();
$client->setDeveloperKey($api_key);
$youtube = new Google_Service_YouTube($client);
$rs = $youtube->videos->listVideos('snippet, statistics, contentDetails', [
'id' => $ids,
]);
$video_id = '0KSOMA3QBU0';
$api_key = 'AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg';
$json_result = file_get_contents ("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$video_id&key=$api_key");
var_dump(json_decode($json_result));
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Answer the question
In order to leave comments, you need to log in
Got a decision.
If you use the same code, but without yii2, you can find out that the problem is with ssl and curl. Why the built-in debugger doesn't display it right away is not clear.
do the following:
1. download the cacert.pem file from here https://curl.haxx.se/docs/caextract.html
2. register it in php.ini --> curl.cainfo = "C:\xampp\php\extras \ssl\cacert.pem"
3. reload the server
Next, I get the same error (which was thrown by yii2), namely:
Warning: count(): Parameter must be an array or an object that implements Countable in ...\vendor\guzzlehttp \guzzle\src\Handler\CurlFactory.php on line 73
Find this line:
if (count($this->handles) >= $this->maxHandles)
and plug it using @
The solution is temporary, but the necessary information can be obtained after:
$api_key = 'super_cool_api_key';
$client = new Google_Client();
$client->setDeveloperKey($api_key);
$youtube = new Google_Service_YouTube($client);
$rs2 = $youtube->search->listSearch('id,snippet', array(
'q' => 'toster forum',
'maxResults' => 7,
));
echo Debug::d($rs2,'resulting...',2);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question