C# 谷歌API OAuth 2代码-YouTube上传
我正在使用下面的代码将视频上传到YouTube。它对我的一个YouTube账户有效,但对另一个账户无效。我只是替换了客户端Id和客户端密码,以便在YouTube帐户之间切换。你知道为什么我的另一个YouTube帐户不能使用它吗C# 谷歌API OAuth 2代码-YouTube上传,c#,.net,youtube-api,google-api,C#,.net,Youtube Api,Google Api,我正在使用下面的代码将视频上传到YouTube。它对我的一个YouTube账户有效,但对另一个账户无效。我只是替换了客户端Id和客户端密码,以便在YouTube帐户之间切换。你知道为什么我的另一个YouTube帐户不能使用它吗 var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) { ClientIdentifie
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();
var provider=new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier=ClientId,
ClientSecret=ClientSecret
};
var auth=新的OAuth2Authenticator(提供者,GetAuthorization);
var youtube=new YouTubeService(new BaseClientService.Initializer())
{
验证器=auth
});
var video=新视频();
video.Snippet=新的VideoSnippet();
video.Snippet.Title=“演示1”;
video.Snippet.Description=“演示1a”;
video.Snippet.Tags=新字符串[]{“tag1”、“tag2”};
video.Snippet.CategoryId=“22”;
video.Status=新的VideoStatus();
video.Status.PrivacyStatus=“private”;
var filePath=@“C:\wildies.wmv”;
var fileStream=newfilestream(filePath,FileMode.Open);
var videosInsertRequest=youtube.Videos.Insert(视频,“片段,状态”,文件流,“视频/*”);
videosInsertRequest.ProgressChanged+=videosInsertRequest\u ProgressChanged;
videosInsertRequest.ResponseReceived+=videosInsertRequest_ResponseReceived;
var uploadThread=新线程(()=>videosInsertRequest.Upload());
uploadThread.Start();
uploadThread.Join();
您无需更改客户端id和密码即可上载到不同的帐户。客户端id和密码定义了开发人员,对于上传将发生的通道,您只需通过该登录进行授权。您无需更改客户端id和密码即可上传到不同的帐户。客户端id和密码定义了开发者,对于上传将发生的频道,您只需要通过该登录进行授权。您在另一个频道打开了youtube服务吗?是的,我打开了。我查过了。你在另一个网站上打开youtube服务了吗?是的,我打开了。我查过了。什么登录?代码如何知道要上传到哪个帐户?有两种方法可以访问API:1)作为独立开发人员,只需提供ClientID和ClientSecret,或2)作为应用程序上的注册用户,完成OAuth2登录流(接受权限,重定向..等等)。目前您正在使用方法1),根据我对您需求的理解,您需要方法2)。什么登录?代码如何知道要上传到哪个帐户?有两种方法可以访问API:1)作为独立开发人员,只需提供ClientID和ClientSecret,或2)作为应用程序上的注册用户,完成OAuth2登录流(接受权限,重定向..等等)。目前您正在使用方法1),根据我对您需求的理解,您需要方法2)。