【问题标题】:Google API OAuth 2 Code - YouTube UploadGoogle API OAuth 2 代码 - YouTube 上传
【发布时间】:2013-09-23 06:53:27
【问题描述】:

我正在使用以下代码将视频上传到 YouTube。它适用于我的一个 YouTube 帐户,但不适用于另一个帐户。我只是替换了 Client Id 和 Client Secret 来在 YouTube 帐户之间切换。关于为什么它不适用于我的其他 YouTube 帐户的任何想法?

var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
                {
                    ClientIdentifier = ClientId,
                    ClientSecret = ClientSecret
                };
                var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);

                var youtube = new YouTubeService(new BaseClientService.Initializer()
                {
                    Authenticator = auth
                });

                var video = new Video();
                video.Snippet = new VideoSnippet();
                video.Snippet.Title = "Demo 1"; 
                video.Snippet.Description = "Demo 1a"; 
                video.Snippet.Tags = new string[] { "tag1", "tag2" };
                video.Snippet.CategoryId = "22"; 
                video.Status = new VideoStatus();
                video.Status.PrivacyStatus = "private"; 
                var filePath = @"C:\wildlife.wmv"; 
                var fileStream = new FileStream(filePath, FileMode.Open);

                var videosInsertRequest = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*");
                videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
                videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

                var uploadThread = new Thread(() => videosInsertRequest.Upload());
                uploadThread.Start();
                uploadThread.Join();

【问题讨论】:

  • 你在另一个打开了youtube服务吗?
  • 是的,我做到了。我查过了。

标签: c# .net youtube-api google-api


【解决方案1】:

您无需更改客户端 ID 和密码即可上传到不同的帐户。 Client id 和 secret 定义了开发者,对于将要上传的频道,您只需要使用该登录进行授权。

【讨论】:

  • 什么登录?代码如何知道要上传到哪个帐户?
  • 有两种方法可以访问 API:1) 作为独立开发者,只需提供 ClientID 和 ClientSecret 或 2) 作为应用程序的注册用户,完成 OAuth2 登录流程(接受权限,被重定向..等等)。目前您正在使用方法 1),根据我对您的要求的理解,您需要方法 2)。
猜你喜欢
  • 1970-01-01
  • 2019-07-28
  • 2015-01-10
  • 2012-05-21
  • 2013-05-23
  • 2020-01-15
  • 2017-12-21
  • 1970-01-01
  • 2017-09-11
相关资源
最近更新 更多