H
H
Herman Martin2018-03-30 13:32:11
YouTube
Herman Martin, 2018-03-30 13:32:11

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"
//

I will try the simplest code
$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,
        ]);

like here https://developers.google.com/youtube/v3/code_samp...
as a result I get the error count(): Parameter must be an array or an object that implements Countable. Moreover, the stack of errors stretches for quite a long time
. Have you encountered something like this?
Initially tried the code:
$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));

But he also did not earn by issuing:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

win7, apache 2.4, php 7.2, yii2.0.14

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Herman Martin, 2018-03-30
@dklight

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 question

Ask a Question

731 491 924 answers to any question