유투브 조회수 가져오는 걸 만들었는데, 두 번째 foreach 부분에서 에러가 납니다.

유투브 조회수 가져오는 걸 만들었는데, 두 번째 foreach 부분에서 에러가 납니다.

QA

유투브 조회수 가져오는 걸 만들었는데, 두 번째 foreach 부분에서 에러가 납니다.

본문

유투브 조회수 가져오는 걸 만들었는데, 두 번째 foreach 부분에서 에러가 납니다. 



function youtubeAPI($url){

    $youtube_api_key = "AIzaSyCacpxaBsQxWJscemhzDDc-_8_JA__VCmw";
    
    parse_str( parse_url( $url, PHP_URL_QUERY ), $u_id );
    //-- https://youtu.be/fdoLXChlJ_4 형태로 들어올수 있으므로 처리 추가
    if($u_id['v'] == ''){
        $url_arr = explode('/', $url);
        $u_id['v'] = end($url_arr);
    }

    $snippet_url = "https://www.googleapis.com/youtube/v3/videos?id=".$u_id['v']."&fields=items&key=".$youtube_api_key."&part=snippet"; //채널 ID 알아낼수있음 -> 구독자수
    $snippet_json = file_get_contents($snippet_url);
    $snippet_ob = json_decode($snippet_json);

    //-- var_dump($snippet_json); 
    
    foreach ( $snippet_ob->items as $data ){
        $channelId = $data->snippet->channelId;       // 채널 ID 
        $uploadDate = $data->snippet->publishedAt;    
            // 업로드일 --------- 업로드일이 등록일이 되는 것임(이유 : 조회수가 이미 많은 영상을 등록 할 수 있음) -- 설정된 날짜(30일 후)의 조회수 - 우리쪽 등록일의 조회수 = ?? 이게 맞는가 ㅋ 확인 필요!
        $thumbnails[120] = $data->snippet->thumbnails->default->url;      // 썸네일 120x90
        $thumbnails[320] = $data->snippet->thumbnails->medium->url;       // 썸네일 320x180      
    }

    $statistics_url = "https://www.googleapis.com/youtube/v3/videos?id=".$u_id['v']."&key=".$youtube_api_key."&part=statistics"; // 영상 좋아요 , 댓글 수 , 조회 수   

     //영상 좋아요 댓글, 조회 수
    $statistics_json = file_get_contents($statistics_url);
    $statistics_ob = json_decode($statistics_json);
    
    foreach ( $statistics_ob->items as $data ){
        $viewCount = $data->statistics->viewCount;          // 조회수      
    }
    
    if($channelId){
        return array('chnnelId'=>$channelId, 'thumnail1'=>$thumbnails[120], 'thumnail2'=>$thumbnails[320], 'viewCount' => $viewCount, 'state' => true);
        // 채널명, 썸네일(가로 120px) URL, 썸네일(가로 320px) URL, 영상조회수, 상태값(영상이 없는경우 false)
    }else{
        return array('state' => false);
    }
}    

 


Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /chriscoinbox/www/include/class/coin.class.php on line 657 
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/videos?id=I3UyRbjU-Mg&t&fields=items&key=AIzaSyCacpxaBsQxWJscemhzDDc-_8_JA__VCmw&part=snippet): failed to open stream: no suitable wrapper could be found in /chriscoinbox/www/include/class/coin.class.php on line 657 
Warning: Invalid argument supplied for foreach() in /chriscoinbox/www/include/class/coin.class.php on line 662 
Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /chriscoinbox/www/include/class/coin.class.php on line 676 
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/videos?id=I3UyRbjU-Mg&t&key=AIzaSyCacpxaBsQxWJscemhzDDc-_8_JA__VCmw&part=statistics): failed to open stream: no suitable wrapper could be found in /chriscoinbox/www/include/class/coin.class.php on line 676 
Warning: Invalid argument supplied for foreach() in /chriscoinbox/www/include/class/coin.class.php on line 679
 
 

이 질문에 댓글 쓰기 :

답변 1

답변을 작성하시기 전에 로그인 해주세요.
전체 42
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT