Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

php - Video uploaded with Youtube API still marked as private after project was approved

I've been struggling with this problem for a while. I'm trying to upload videos to Youtube using the Youtube V3 API. I've added the correct scopes to the OAuth Consent screen and the project was approved recently (went through the whole audit thingie), but the videos are still marked as private when they are uploaded.

I've tested with different video files on different accounts. I've created new API keys, even restricted the keys and still no success.

I'm using the latest version of the Google APIs Client Library for PHP.

Any help would be appreciated. I don't even know how to contact Google for support on this one.

Edit: This is the code snippet that handles video upload


    //Code that retrieves the api auth data is not included
    //Also not included is the code that prepares the video path, title, description and category

    $google_client = new Google_Client();

    // Offline because we need to get refresh token
    $google_client->setAccessType('offline');

    // Name of the google application
    $google_client->setApplicationName($appName);
    
    // Set the client_id
    $google_client->setClientId($clientId);

    // Set the client_secret
    $google_client->setClientSecret($clientSecret);

    // Redirects to same url
    $google_client->setRedirectUri($scriptUri);

    // Set the api key
    $google_client->setDeveloperKey($apiKey);

    // Load required scopes
    $google_client->setScopes(array(
        'https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/userinfo.profile'
    ));

    // Refresh token
    $google_client->refreshToken($refresh_token);

    // Get access token
    $new_access_token = $google_client->getAccessToken();

    // Set access token
    $google_client->setAccessToken($new_access_token);

    // Define service object for making API requests.
    $youtube_service = new Google_Service_YouTube($google_client);

    // Define the $youtube_video object, which will be uploaded as the request body.
    $youtube_video = new Google_Service_YouTube_Video();

    // Add 'snippet' object to the $youtube_video object.
    $video_snippet = new Google_Service_YouTube_VideoSnippet();

    // Add category, title, description
    $video_snippet->setCategoryId($video_category);
    $video_snippet->setTitle($video_title);
    $video_snippet->setDescription($video_description);

    $youtube_video->setSnippet($video_snippet);

    // Add 'status' object to the $youtube_video object.
    $video_status = new Google_Service_YouTube_VideoStatus();
    $video_status->setPrivacyStatus('public');
    $youtube_video->setStatus($video_status);

    //Get MIME
    $file_info = finfo_open(FILEINFO_MIME_TYPE);
    $mime_type = finfo_file($file_info, $video_path);

    $upload = $youtube_service->videos->insert('snippet,status', $youtube_video, array(
        'data' => file_get_contents($video_path),
        'mimeType' => $mime_type,
        'uploadType' => 'multipart'
    ));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...