• Google api (youtube/v3/subscriptions) получил id пользователя как получить список каналов на который он подписан?

    @pyro338
    ну я делал примерно так:

    public function getSubscriptionsById($channelId, $part = ['contentDetails', 'id', 'snippet', 'subscriberSnippet'])
        {
            $API_URL = 'https://www.googleapis.com/youtube/v3/subscriptions';
            $params = [
                'channelId' => $channelId,
                'part' => implode(', ', $part),
                'maxResults' => 40
            ];
    
            $apiData = $this->api_get($API_URL, $params);
    
            return $this->decodeMultiple($apiData);
        }
    
        /**
         * Using CURL to issue a GET request
         *
         * @param $url
         * @param $params
         * @return mixed
         * @throws \Exception
         */
        public function api_get($url, $params)
        {
            //set the youtube key
            $params['key'] = \Illuminate\Support\Facades\Config::get('youtube.key');
    
            //boilerplates for CURL
            $tuCurl = curl_init();
            curl_setopt($tuCurl, CURLOPT_URL, $url . (strpos($url, '?') === false ? '?' : '') . http_build_query($params));
            if (strpos($url, 'https') === false) {
                curl_setopt($tuCurl, CURLOPT_PORT, 80);
            } else {
                curl_setopt($tuCurl, CURLOPT_PORT, 443);
            }
    
            curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
            $tuData = curl_exec($tuCurl);
            if (curl_errno($tuCurl)) {
                throw new \Exception('Curl Error : ' . curl_error($tuCurl));
            }
    
            return $tuData;
        }
    
        /**
         * Decode the response from youtube, extract the multiple resource object.
         *
         * @param  string $apiData the api response from youtube
         * @throws \Exception
         * @return \StdClass  an Youtube resource object
         */
        public function decodeMultiple(&$apiData)
        {
            $resObj = json_decode($apiData);
            if (isset($resObj->error)) {
                $msg = "Error " . $resObj->error->code . " " . $resObj->error->message;
                if (isset($resObj->error->errors[0])) {
                    $msg .= " : " . $resObj->error->errors[0]->reason;
                }
    
                throw new \Exception($msg);
            } else {
                $itemsArray = $resObj->items;
                if (!is_array($itemsArray)) {
                    return false;
                } else {
                    return $itemsArray;
                }
            }
        }
    Ответ написан
    Комментировать