私は自分のチャットボットをWinformsとC#でYouTube用に取り組んでいます。既にTwitchで動作しており、C#APIを使用してYoutubeの機能を再現しようとしています。チャットメッセージは問題なくダウンロードできますが、チャットメッセージを作成すると、403、「不十分なアクセス権」エラーが表示されて頭痛の原因になります。完全なエラーメッセージは、私が見つけることができるとまだこれを引き起こしている正確に何のように空が出ているほとんどのものを試してみたいくつか検索した後YouTube .NET API - チャットメッセージを作成する際に許可の問題が発生する
Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]
です。私はそれが許可の問題だと私は明らかに何かを設定する必要がありますが、私は何を把握することはできません。私のコードは以下の通りであり、データの読み込みには間違いなく働いています...しかし、なぜそれが書き込みにはうまくいかないのか分かりません。
public class YouTubeDataWrapper
{
private YouTubeService youTubeService;
private string liveChatId;
private bool updatingChat;
private int prevResultCount;
public List<YouTubeMessage> Messages { get; private set; }
public bool Connected { get; private set; }
public bool ChatUpdated { get; set; }
//public Authorisation Authorisation { get; set; }
//public AccessToken AccessToken { get; set; }
public YouTubeDataWrapper()
{
this.Messages = new List<YouTubeMessage>();
}
public async void Connect()
{
Stream stream = new FileStream("client_secrets.json", FileMode.Open);
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, new[] { YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None, new FileDataStore(this.GetType().ToString()));
stream.Close();
stream.Dispose();
this.youTubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.GetType().ToString()
});
var res = this.youTubeService.LiveBroadcasts.List("id,snippet,contentDetails,status");
res.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Persistent;
res.Mine = true;
//res.BroadcastStatus = LiveBroadcastsResource.ListRequest.BroadcastStatusEnum.Active;
var resListResponse = await res.ExecuteAsync();
IEnumerator<LiveBroadcast> ie = resListResponse.Items.GetEnumerator();
while (ie.MoveNext() && string.IsNullOrEmpty(this.liveChatId))
{
LiveBroadcast livebroadcast = ie.Current;
string id = livebroadcast.Snippet.LiveChatId;
if (!string.IsNullOrEmpty(id))
{
this.liveChatId = id;
this.Connected = true;
}
bool? def = livebroadcast.Snippet.IsDefaultBroadcast;
string title = livebroadcast.Snippet.Title;
LiveBroadcastStatus status = livebroadcast.Status;
}
}
public async void UpdateChat()
{
if (!this.updatingChat)
{
if (!string.IsNullOrEmpty(this.liveChatId) && this.Connected)
{
this.updatingChat = true;
var livechat = this.youTubeService.LiveChatMessages.List(this.liveChatId, "id,snippet,authorDetails");
var livechatResponse = await livechat.ExecuteAsync();
PageInfo pageInfo = livechatResponse.PageInfo;
this.ChatUpdated = false;
if (pageInfo.TotalResults.HasValue)
{
if (!this.prevResultCount.Equals(pageInfo.TotalResults.Value))
{
this.prevResultCount = pageInfo.TotalResults.Value;
this.ChatUpdated = true;
}
}
if (this.ChatUpdated)
{
this.Messages = new List<YouTubeMessage>();
foreach (var livemessage in livechatResponse.Items)
{
string id = livemessage.Id;
string displayName = livemessage.AuthorDetails.DisplayName;
string message = livemessage.Snippet.DisplayMessage;
YouTubeMessage msg = new YouTubeMessage(id, displayName, message);
string line = string.Format("{0}: {1}", displayName, message);
if (!this.Messages.Contains(msg))
{
this.Messages.Add(msg);
}
}
}
this.updatingChat = false;
}
}
}
public async void SendMessage(string message)
{
LiveChatMessage liveMessage = new LiveChatMessage();
liveMessage.Snippet = new LiveChatMessageSnippet() { LiveChatId = this.liveChatId, Type = "textMessageEvent", TextMessageDetails = new LiveChatTextMessageDetails() { MessageText = message } };
var insert = this.youTubeService.LiveChatMessages.Insert(liveMessage, "snippet");
var response = await insert.ExecuteAsync();
if (response != null)
{
}
}
}
問題の主なコードは、メッセージを送る方法です。私は役に立たないようにしようとすることができるすべてにUserCredentialsの範囲を変更しようとしました。何か案は?
ユーザーはGoogleアカウントでログインしていますか? – Bobby
これは、コードを最初に実行したときのプロセスを通っていなければなりません(そうでなければ、わからない)。 – mikelomaxxx14
"処理中"? 通常、誰でもあなたのアプリケーションを開き(まだサインインしていない)、Googleは彼に自分の身元を尋ねなければならず、ユーザーはユーザー名とパスワードをGoogleサービスに提供する必要があります。 これは実装されていますか? – Bobby