小编Ani*_*tak的帖子

Youtube API v3:使用服务帐户访问 YouTube 视频

我正在尝试使用 Google 服务帐户在 .NET 中列出来自 YouTube Data API v3 的视频。我已经激活了 YouTube API,创建了帐户服务,但每当我尝试列出我的频道中的视频时,即使我确实上传了视频,它也会显示 0 个视频。能否请你帮忙 ?谢谢。

这是代码 -

string[] scopes = new string[] 
{    
    YouTubeAnalyticsService.Scope.YtAnalyticsReadonly, 
    YouTubeAnalyticsService.Scope.YtAnalyticsMonetaryReadonly, 
    "https://www.googleapis.com/auth/youtube.force-ssl" 
};

// service account credential
GoogleCredential credential = GoogleCredential.FromFile(SecretPath).CreateScoped(scopes);

var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = channelinfo.AnalyticsAPIFileDataStore
});

Dictionary<string, DateTime?> videoIds = new Dictionary<string, DateTime?>();

var channelResourcesList = youtubeService.Channels.List("contentDetails");
channelResourcesList.Id = channelinfo.ChannelId;
var listResult = channelResourcesList.Execute();
string playListId = listResult.Items[0]?.ContentDetails.RelatedPlaylists.Uploads;

var listOfVideos = youtubeService.PlaylistItems.List("snippet");

listOfVideos.PlaylistId = playListId;
var nextPageToken …
Run Code Online (Sandbox Code Playgroud)

.net youtube-api service-accounts youtube-data-api

6
推荐指数
1
解决办法
4991
查看次数

redirect_uri_mismatch 请求中的重定向 URI 与 OAuth 客户端授权的不匹配

我有以下客户机密

{
  "web": {
    "client_id": "testid",
    "project_id": "testproj",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://www.googleapis.com/oauth2/v3/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "test-sec",
    "redirect_uris": [
      "https://localhost:8080/oauth2callback"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到

“错误:redirect_uri_mismatch 请求中的重定向 URI http://127.0.0.1:8414/authorize/与为 OAuth 客户端授权的不匹配。

要更新授权的重定向 URI,请访问:"。您能否提出建议,如何修复它。

我正在使用 C#。我已经用这个创建了凭据 -

GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes,
                                             "user",
                                              CancellationToken.None, 
                                              new FileDataStore(Directory.GetCurrentDirectory() + "\\AccessToken\\" , 
                                             true)).Result; 
Run Code Online (Sandbox Code Playgroud)

但是第一次,它弹出登录,一旦我登录,它就创建了 Google.Apis.Auth.OAuth2.Responses.TokenResponse-user文件夹中了文件。有没有办法绕过第一次登录?

谢谢。

google-api youtube-api google-oauth youtube-data-api

4
推荐指数
2
解决办法
1万
查看次数