我正在开发Java代码,以使用服务帐户身份验证检索相应资产ID的视频ID。我已按照下面提到的步骤操作。 步骤1:编写Java程序以使用服务帐户从Google身份验证中检索访问令牌。 代码用于获取access_token:
String EmailId = "XXXXXXXXXXX@developer.gserviceaccount.com";
//passing Scope
@SuppressWarnings({ "unchecked", "rawtypes" })
List<String>scops = new <String>ArrayList();
scops.add("https://www.googleapis.com/auth/youtubepartner");
final HttpTransport TRANSPORT = new NetHttpTransport();
final JsonFactory JSON_FACTORY = new JacksonFactory();
// Create a listener for automatic refresh OAuthAccessToken
List<CredentialRefreshListener> list = new ArrayList<CredentialRefreshListener>();
list.add(new CredentialRefreshListener() {
@Override
public void onTokenResponse(Credential credential,
TokenResponse tokenResponse) throws IOException {
System.out.println(tokenResponse.toPrettyString());
}
public void onTokenErrorResponse(Credential credential,
TokenErrorResponse tokenErrorResponse)
throws IOException {
System.err.println("Error: "
+ tokenErrorResponse.toPrettyString());
}
});
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(EmailId)
.setServiceAccountScopes(scops)
.setServiceAccountPrivateKeyFromP12File(new File("test.p12"))
.setRefreshListeners(list)
.build();
credential.refreshToken();
步骤2:在步骤1中获取的访问令牌作为参数传递到下面提到的URL中以获取Youtube视频ID
示例网址为:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
}
}
已启用“GOOGLE COULD JSON API”和“YOUTUBE DATA API”。 请问有谁可以帮我解决这个问题吗?
答案 0 :(得分:1)
我从之前的项目中了解到,您需要在Google控制台中启用API。我会先试试。
答案 1 :(得分:0)
您尝试使用Youtube的Content ID API端点/ youtube / partner / v1 / claimSearch。
此端点不是Youtube Data API的一部分,只有参与“Youtube合作伙伴计划”才能访问该端点。否则它甚至没有在Developer's Console中列出。
此处提供更多信息:https://developers.google.com/youtube/partner/
注意:YouTube Content ID API供YouTube内容合作伙伴使用,并非所有开发者或所有YouTube用户都可以访问。如果您没有将YouTube Content ID API视为Google Developers Console中列出的服务之一,请访问www.youtube.com/partner以了解有关YouTube合作伙伴计划的更多信息。