我尝试将视频上传到 Youtube 。已成功将视频上传到帐户的频道。 之后我创建了名为" Deneme1"的新频道。我试图用api上传到那个频道;但上传到主。
我的代码:
public static string UploadVideo(string FilePath, string Title, string Description)
{
YouTubeRequestSettings settings;
YouTubeRequest request;
string devkey = "api key";
string username = "mail@gmail.com";
string password = "password";
settings = new YouTubeRequestSettings("Deneme1", devkey, username, password) { Timeout = 10000000 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.Keywords = "asd";
newVideo.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv");
Video createdVideo = request.Upload(newVideo);
return createdVideo.VideoId;
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
string videopath, videotitle, videodesc;
videopath = @"C:\Users\Ercin\Dropbox\Cloudy\Visual Studio\Projects\videoupload\videoupload\badstart.flv";
videotitle = "test title";
videodesc = "test description";
UploadVideo(videopath, videotitle, videodesc);
}
catch (Exception exception)
{
Response.Write("Upload failed: " + exception.Message);
}
任何帮助都会很棒!
答案 0 :(得分:2)
此代码对我来说很合适,上传到我在用户名中输入ChannelId的特定频道。
<?php
session_start();
$_SESSION['key']['userid'] = 1;
class IUser
{
public function User( $arg )
{
switch( $arg ) {
case "online":
return self::CheckKey();
break;
}
}
public function CheckKey()
{
if( isset( $_SESSION['key']['userid'] ) ) {
return true;
} else {
return false;
}
}
}
$user = new IUser();
if( $user->User( "online" ) ) {
echo "user online";
} else {
echo "user offline";
}
?>
答案 1 :(得分:1)
从头开始(对一些人有帮助)我会告诉你我做了什么:
thiago.adriano26
在答案中的代码。C:\Users\User\AppData\Roaming\Google.Apis.Auth\Google.Apis.Auth.OAuth2.Responses.TokenResponse-<UserId>
生成一个令牌。这似乎将使用过的UserId
链接到实际频道。只要有,两者之间的这种联系就会存在。删除它,或使用其他UserId(每个频道都有自己的UserId
和ChannelId
,请参阅此处:https://support.google.com/youtube/answer/3250431?hl=en),您可以从浏览器中选择新频道。