这个错误让我抓狂。据我所知,我已正确按照说明进行操作。我的范围是 YOUTUBE_FORCE_SSL。无奈之下,我尝试添加所有 Google Plus 范围,但没有成功。在设备、模拟器和 Google Api Explorer 中仍然出现相同的错误。我尝试评论的视频是公开的。我有 Google+ 个人资料,并且在尝试发表评论时使用它登录。
这是完整的错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.commentThread",
"location" : "Authorization",
"locationType" : "header",
"message" : "The callers YouTube account is not connected to Google+.",
"reason" : "ineligibleAccount"
} ],
"message" : "The callers YouTube account is not connected to Google+."
}
这是我的代码:
try {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("part", "snippet");
CommentThread commentThread = new CommentThread();
CommentThreadSnippet snippet = new CommentThreadSnippet();
Comment topLevelComment = new Comment();
CommentSnippet commentSnippet = new CommentSnippet();
commentSnippet.set("textOriginal", textComment);
commentSnippet.set("channelId", channelId);
commentSnippet.set("videoId", ytId);
topLevelComment.setSnippet(commentSnippet);
snippet.setTopLevelComment(topLevelComment);
commentThread.setSnippet(snippet);
YouTube.CommentThreads.Insert commentThreadsInsertRequest = mService.commentThreads().insert(parameters.get("part"), commentThread);
CommentThread response = commentThreadsInsertRequest.execute();
Log.i("COMMENT:", response.toString());
}
从 Api Explorer 添加屏幕截图:
你能得到CommentThreads: insert吗?使用 API Explorer?如果是,怎么办?
我看过类似问题的答案here他们没有解决这个问题。
感谢任何帮助。
编辑 1
经过进一步测试。我拥有的旧帐户一切正常。到目前为止,我已经尝试查看哪些设置可能不同。
如果我切换到 YouTube 品牌帐户,这也适用。
问题仍然存在,它不适用于所有 Google 帐户,即使它们也是 Google+ 帐户也是如此。该错误似乎暗示请求不是来自 Google+ 帐户。如果 Google 可以澄清确切原因,那就太好了。
此外,在征得帐户所有者的许可后,是否可以通过编程方式使帐户有资格发表评论?怎么办?
编辑2
根据 this page错误原因是这样的:
The YouTube account used to authorize the API request must be merged with the user's Google account to insert a comment or comment thread.
如何在应用程序中完成此操作?
编辑3
我想可以找到答案here .如果没有 YouTube channel ,您将无法发表评论。
问题是,除非您拥有私有(private) YouTube channel 或使用您的品牌帐户登录,否则您无法发表评论。使用 Google 在说明中提供的模型登录不允许使用品牌帐户登录,它们在帐户选择器中不可见。
结果是您可以使用拥有 YouTube 品牌帐户的帐户登录,但您将无法使用该帐户发表评论,并且由于您无法选择品牌帐户,因此无法解决除非您要求用户也创建一个私有(private) channel 。错误消息应该是这样的:
The callers YouTube account is not a YouTube Channel Account.
最佳答案
如果您创建了一个新帐户并且没有对任何 YouTube 视频发表评论,则会抛出错误:“来电者 YouTube 帐户未连接到 Google+。”
解决方案:至少使用新帐户在任何 YouTube 视频中手动发表评论,然后尝试使用 API。它工作顺利。
关于java - 评论线程 : insert gives 403 Forbidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50828577/