Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在使用youtube api时出现访问禁止错误?_Youtube_Youtube Data Api - Fatal编程技术网

为什么在使用youtube api时出现访问禁止错误?

为什么在使用youtube api时出现访问禁止错误?,youtube,youtube-data-api,Youtube,Youtube Data Api,使用YouTube api v3将视频上载到YouTube时,我遇到以下错误: Google.Apis.Requests.RequestError Access forbidden. The request may not be properly authorized. [403] Errors [ Message[Access forbidden. The request may not be properly authorized.] Location[ - ] Reason[for

使用YouTube api v3将视频上载到YouTube时,我遇到以下错误:

Google.Apis.Requests.RequestError
Access forbidden. The request may not be properly authorized. [403]
Errors [
    Message[Access forbidden. The request may not be properly authorized.] Location[ - ] Reason[forbidden] Domain[youtube.common]
]
该应用程序将成功上传几段视频,然后随机抛出403错误

配额限制是每天一百万次查询,我只使用了大约1%。 频道上已经有大约1200个视频是用同一个应用程序上传的,现在突然在过去几天里我发现了这个错误。我曾尝试将视频上传到另一个频道,但没有遇到任何问题,因此问题似乎是针对这一频道的。好像它被节流了,但我不知道为什么

我没有违反任何服务条款,视频是原创的,账户信誉良好,我在限额内

如果还有其他限制,为什么谷歌不在api参考中记录?这样我们就可以根据政策设计我们的应用程序

如果你遵循规范,然后谷歌在后端有一套不同的规则,你就不可能构建一个应用程序,你只能猜测自己是什么,不允许做什么

使用此代码:

using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

namespace Google.Apis.YouTube.Samples
{
  /// <summary>
  /// YouTube Data API v3 sample: upload a video.
  /// Relies on the Google APIs Client Library for .NET, v1.7.0 or higher.
  /// See https://developers.google.com/api-client-library/dotnet/get_started
  /// </summary>
  internal class UploadVideo
  {
    [STAThread]
    static void Main(string[] args)
    {
      Console.WriteLine("YouTube Data API: Upload Video");
      Console.WriteLine("==============================");

      try
      {
        new UploadVideo().Run().Wait();
      }
      catch (AggregateException ex)
      {
        foreach (var e in ex.InnerExceptions)
        {
          Console.WriteLine("Error: " + e.Message);
        }
      }

      Console.WriteLine("Press any key to continue...");
      Console.ReadKey();
    }

    private async Task Run()
    {
      UserCredential credential;
      using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
      {
        credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
            // This OAuth 2.0 access scope allows an application to upload files to the
            // authenticated user's YouTube channel, but doesn't allow other types of access.
            new[] { YouTubeService.Scope.YoutubeUpload },
            "user",
            CancellationToken.None
        );
      }

      var youtubeService = new YouTubeService(new BaseClientService.Initializer()
      {
        HttpClientInitializer = credential,
        ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
      });

      var video = new Video();
      video.Snippet = new VideoSnippet();
      video.Snippet.Title = "Default Video Title";
      video.Snippet.Description = "Default Video Description";
      video.Snippet.Tags = new string[] { "tag1", "tag2" };
      video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
      video.Status = new VideoStatus();
      video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
      var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.

      using (var fileStream = new FileStream(filePath, FileMode.Open))
      {
        var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
        videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
        videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

        await videosInsertRequest.UploadAsync();
      }
    }

    void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
    {
      switch (progress.Status)
      {
        case UploadStatus.Uploading:
          Console.WriteLine("{0} bytes sent.", progress.BytesSent);
          break;

        case UploadStatus.Failed:
          Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
          break;
      }
    }

    void videosInsertRequest_ResponseReceived(Video video)
    {
      Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
    }
  }
}
使用系统;
使用System.IO;
运用系统反思;
使用系统线程;
使用System.Threading.Tasks;
使用Google.api.Auth.OAuth2;
使用Google.api.Services;
使用Google.api.Upload;
使用Google.api.Util.Store;
使用Google.api.YouTube.v3;
使用Google.api.YouTube.v3.Data;
名称空间Google.api.YouTube.Samples
{
/// 
///YouTube数据API v3示例:上传视频。
///依赖于.NET版本1.7.0或更高版本的Google API客户端库。
///看https://developers.google.com/api-client-library/dotnet/get_started
/// 
内部类上传视频
{
[状态线程]
静态void Main(字符串[]参数)
{
Console.WriteLine(“YouTube数据API:上传视频”);
Console.WriteLine(“===========================================”);
尝试
{
新建上载视频().Run().Wait();
}
捕获(聚合异常)
{
foreach(ex.InnerExceptions中的变量e)
{
Console.WriteLine(“错误:+e.Message”);
}
}
Console.WriteLine(“按任意键继续…”);
Console.ReadKey();
}
专用异步任务运行()
{
用户凭证;
使用(var stream=newfilestream(“client_secrets.json”、FileMode.Open、FileAccess.Read))
{
凭证=等待GoogleWebAuthorizationBroker.AuthorizationAsync(
GoogleClientSecrets.Load(stream.Secrets),
//此OAuth 2.0访问范围允许应用程序将文件上载到
//已验证用户的YouTube频道,但不允许其他类型的访问。
新[]{YouTubeService.Scope.YoutubeUpload},
“用户”,
取消令牌。无
);
}
var youtubeService=new youtubeService(new BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=Assembly.GetExecutionGassembly().GetName().Name
});
var video=新视频();
video.Snippet=新的VideoSnippet();
video.Snippet.Title=“默认视频标题”;
video.Snippet.Description=“默认视频描述”;
video.Snippet.Tags=新字符串[]{“tag1”、“tag2”};
video.Snippet.CategoryId=“22”//请参阅https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status=新的VideoStatus();
video.Status.PrivacyStatus=“未列出”;//或“私有”或“公共”
var filePath=@“REPLACE_ME.mp4”;//替换为实际电影文件的路径。
使用(var fileStream=newfilestream(filePath,FileMode.Open))
{
var videosInsertRequest=youtubeService.Videos.Insert(视频,“片段,状态”,文件流,“视频/*”;
videosInsertRequest.ProgressChanged+=videosInsertRequest\u ProgressChanged;
videosInsertRequest.ResponseReceived+=videosInsertRequest_ResponseReceived;
等待videosInsertRequest.UploadAsync();
}
}
void videosInsertRequest_进度已更改(Google.api.Upload.IUploadProgress进度)
{
开关(进度状态)
{
案例上传状态。上传:
WriteLine(“{0}字节已发送。”,progress.BytesSent);
打破
案例上载状态。失败:
WriteLine(“一个错误阻止上载完成。\n{0}”,progress.Exception);
打破
}
}
接收到无效视频请求/响应(视频)
{
WriteLine(“视频id{0}已成功上载。”,Video.id);
}
}
}

我开始得到同样的东西。我已经发了一封支持邮件,正在等待回复。似乎很多人都有这个问题。如果您收到支持部门的回复,请告知我们。ThanksI从支持人员那里得到了半个答案:“目前,我们的工程师已经意识到了这个问题,并且仍在努力解决它。目前,我无法提供解决方案的具体时间表,但是一旦我们的工程师应用了修复,它将自动在我们的系统中实施。”