首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过YouTube数据接口上传的视频正在变为私有

通过YouTube数据接口上传的视频正在变为私有
EN

Stack Overflow用户
提问于 2020-12-11 02:09:08
回答 1查看 166关注 0票数 0

我尝试过通过composer使用YouTube Data API将视频上传到YouTube频道:

代码语言:javascript
复制
    "require": {
        "google/apiclient": "^2.7",
        "hybridauth/hybridauth": "~3.4.0",
        "guzzlehttp/guzzle": "^7.0"
    }

视频上传成功,但YouTube会将上传的每个视频标记为私有。有没有人知道如何修复这种情况?

代码语言:javascript
复制
    public function upload_video_on_youtube($id, $arr_data)
    {
        $result_data = array();
        $channel_id = $id;
        $uploaded = false;
        $stopper = 0;
        while ($uploaded == false && $stopper == 0) {
            $arr_data['summary'] = $this->getrandomstring(10);
            $arr_data['title'] = $this->getrandomstring(10);
            $client = new Google_Client();
            $arr_token = $this->getAccessToken($channel_id);
            if ($arr_token['error'] == false) {
                $res = array();
                $accessToken = array(
                    'access_token' => $arr_token['access_token']
                );
                $client->setAccessToken($accessToken);
                $service = new Google_Service_YouTube($client);
                $video = new Google_Service_YouTube_Video();
                $videoSnippet = new Google_Service_YouTube_VideoSnippet();
                $videoSnippet->setDescription($arr_data['summary']);
                $videoSnippet->setTitle($arr_data['title']);
                $video->setSnippet($videoSnippet);
                $videoStatus = new Google_Service_YouTube_VideoStatus();
                $videoStatus->setPrivacyStatus('unlisted');
                $video->setStatus($videoStatus);
                try {
                    $response = $service->videos->insert(
                        'snippet,status',
                        $video,
                        array(
                            'data' => file_get_contents($arr_data['video_path']),
                            'mimeType' => 'video/*',
                            'uploadType' => 'multipart'
                        )
                    );
                    if (isset($response->id)) {
                        $video_id = $response->id;
                        $res['error'] = false;
                        $res['response'] = $video_id;
                        array_push($result_data, $res);
                        $uploaded = true;
                        return $result_data;
                    }
                } catch (Exception $e) {
                    if (401 == $e->getCode()) {
                        // echo ($arr_token['email'] . " Youtube  Access token expired");
                        $refresh_token = $this->get_refersh_token($channel_id);
                        $client = new GuzzleHttp\Client(['base_uri' => 'https://accounts.google.com']);
                        $response = $client->request('POST', '/o/oauth2/token', [
                            'form_params' => [
                                "grant_type" => "refresh_token",
                                "refresh_token" => $refresh_token,
                                "client_id" => $arr_token['client_id'],
                                "client_secret" => $arr_token['client_secret'],
                            ],
                        ]);
                        $data = json_decode($response->getBody());
                        $data->refresh_token = $refresh_token;
                        $this->update_access_token($channel_id, json_encode($data));
                        $uploaded = false;
                    } elseif (403 == $e->getCode()) {
                        // echo ($arr_token['email'] . '  Youtube channel quota exceeded');
                        $channel_id = $channel_id + 1;
                        $uploaded = false;
                    }
                }
            } else if ($arr_token['error'] == true) {
                $res['error'] = true;
                $res['response'] = "Your Daily Upload Quota is Exceeded";
                array_push($result_data, $res);
                $stopper = 1;
                return $result_data;
            }
        }
    }
EN

Stack Overflow用户

发布于 2020-12-11 03:54:52

如果你查看videos.insert的文档,你会发现所有未通过验证的应用上传的视频都将被设置为私有。

通过验证过程后,您就可以将视频设置为公共视频

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65239982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档