【发布时间】:2021-07-16 11:47:10
【问题描述】:
我知道之前有人问过这个问题,并且有一个经过验证的答案here,但那个灵魂对我不起作用。 我想从我的自定义软件回复我频道的 cmets。首先,我在 google 控制台中创建了一个服务帐户并创建了一个密钥并下载了一个包含该密钥的文件(请参阅下面代码中的 file.json)。我使用代码获得了我的 Oauth2.0 令牌:
try {
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream("file.json"))
.createScoped(Collections.singleton(YouTubeScopes.YOUTUBE_FORCE_SSL));
String token = credentials.refreshAccessToken().getTokenValue();
} catch (IOException e) {
e.printStackTrace();
}
file.json 文件来自 google 服务帐户控制台。它包括私钥、client_id、客户电子邮件和其他详细信息。这段代码一切正常,我成功收到了访问令牌。但是当我尝试向https://youtube.googleapis.com/youtube/v3/comments?part=snippet 发送一个http POST 请求时,需要解释here 的json 正文,我收到以下错误:
{
"error": {
"code": 403,
"message": "The YouTube account used to authorize the API request must be merged with the user's Google account.",
"errors": [
{
"message": "The YouTube account used to authorize the API request must be merged with the user's Google account.",
"domain": "youtube.comment",
"reason": "ineligibleAccount",
"location": "Authorization",
"locationType": "header"
}
]
}
}
提前致谢。
【问题讨论】:
标签: java youtube-api youtube-data-api google-api-java-client service-accounts