2016-03-09 137 views
3

我越來越低於錯誤,我想讓所有評論發佈在YouTube視頻上。Google.Apis.Requests.RequestError權限不足[403]

所以基本上我傳遞視頻ID,我想獲得與視頻

Google.Apis.Requests.RequestError
沒有足夠的許可[403]

錯誤[消息相關聯的所有評論[沒有足夠的權限]地址[ - ]原因[insufficientPermissions]域[全球]

這裏是我的代碼:

protected void btnGetVideoDesc_Click(object sender, EventArgs e) 
{ 
    string videoId = txtVideoID.Text; 
    YoutubeVideo video = new YoutubeVideo(videoId); 
    lblTitle.Text = video.title; 
    lblPublishedDate.Text = video.publishdate.ToShortDateString(); 
} 

public class YoutubeVideo 
{ 
    public string id, title, description ; 
    public DateTime publishdate; 

    public YoutubeVideo(string id) 
    { 
     this.id = id; 
     YoutubeAPI.GetVideoInfo(this); 
    } 
} 

public class YoutubeAPI 
{ 
    private static YouTubeService ytService = Auth(); 

    private static YouTubeService Auth() 
    { 
     UserCredential creds; 
     var service = new YouTubeService(); 
     try 
     { 
      using (var stream = new FileStream(@"C:\v-mmarat\Project\EMEA_Development\YoutubeWebCrawling\YoutubeWebCrawling\youtube_client_secret.json", FileMode.Open, FileAccess.Read)) 
      { 
       creds = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, 
        new[] { YouTubeService.Scope.YoutubeReadonly }, "user", CancellationToken.None, 
        new FileDataStore("YoutubeAPI") 
        ).Result; 
      } 
      service = new YouTubeService(new BaseClientService.Initializer() 
      { 
       HttpClientInitializer = creds, 
       ApplicationName = "YoutubeAPI", 
       ApiKey = "My_API_Key" 

      }); 
     } 
     catch (Exception e) 
     { } 
     return service; 
    } 

    public static void GetVideoInfo(YoutubeVideo video) 
    { 
     try 
     { 
      //This code work perfectly 
      var videoRequest = ytService.Videos.List("snippet"); 

      videoRequest.Id = video.id; 

      var response = videoRequest.Execute(); 
      if (response.Items.Count > 0) 
      { 
       video.title = response.Items[0].Snippet.Title; 
       video.description = response.Items[0].Snippet.Description; 
       video.publishdate = response.Items[0].Snippet.PublishedAt.Value; 
      }    




     else 
      { 
       //error 
      } 

      var CommentRequest = ytService.Comments.List("snippet"); 

      videoRequest.Id = video.id; 

      //Getting error at this line after CommentRequest.Execute(); 
      var Commentresponse = CommentRequest.Execute(); 
      if (Commentresponse.Items.Count > 0) 
      { 
       video.title = Commentresponse.Items[0].Snippet.ChannelId; 
       video.description = Commentresponse.Items[0].Snippet.TextDisplay; 
       video.publishdate = Commentresponse.Items[0].Snippet.PublishedAt.Value; 
      } 
      else 
      { 
       //error 
      } 
     } 
     catch (Exception e) 
     { } 
    } 

回答

0

我知道這個答案有點晚,但這是爲我修復的。希望它可以幫助別人。

我正在收到相同的權限被拒絕的錯誤。在將YouTubeService.Scope.YoutubeForceSsl項目添加到範圍列表後,我能夠提出評論。

此外,它看起來像你的代碼是不正確的。您將需要根據VideoId拉取CommentThreads幷包含回覆(如果您需要的話)。

您將無法使用評論爲視頻提出評論。

var threadsRequest = Client.CommentThreads.List("snippet,replies"); 

threadsRequest.VideoId = videoId; 

var response = threadsRequest.Execute(); 
2

這是一個真的反應遲緩,但我也有類似的問題。我的項目使用YouTube API將視頻上傳到帳戶,並在代碼的另一部分中再次使用它來通過ID搜索視頻以檢查其狀態。

我的問題是我使用相同的OAuth憑據上傳,然後也用於搜索視頻。

這是失敗的,因爲我已經在上傳時設置了YouTube範圍,這不是搜索視頻的正確範圍。

我對這個簡單的解決方案是創建通過谷歌開發者控制檯的另一組OAuth認證的(類型爲「其他」中),下載JSON文件,並使用這些信息來獲得不同的訪問令牌的搜索部分我碼。

希望這可以幫助別人。

0

在授權更改「用戶」到「管理」。

+0

tbh..This應該是一個評論...但缺乏代表... – ZF007

相關問題