我使用YouTube数据API使我为客户制作的基于网络的客户端能够连接到youtube并列出其帐户中的视频。直到客户将这些服务闲置了90天之后,凭据才被取消。
我创建了一个新凭据,但现在不起作用,我也找不到解决方案。客户端使用OAuth授权,然后执行YouTube Youtube.Search.list
try{
youtube = getYouTubeService(XXXXXX);
}catch(NullPointerException e){
throw new BasicException("You must connect this system to YouTube before you can load videos. You may do this in Settings.");
}
HashMap<String, String> parameters = new HashMap<String,String>();
parameters.clear();
parameters.put("part", "id,snippet");
parameters.put("forMine", "true");
parameters.put("type", "video");
parameters.put("maxResults", "50");
YouTube.Search.List searchListMineRequest = youtube.search().list(parameters.get("part").toString());
if (parameters.containsKey("maxResults")) {
searchListMineRequest.setMaxResults(Long.parseLong(parameters.get("maxResults").toString()));
}
if (parameters.containsKey("forMine") && parameters.get("forMine") != "") {
boolean forMine = (parameters.get("forMine") == "true") ? true : false;
searchListMineRequest.setForMine(forMine);
}
if (parameters.containsKey("type") && parameters.get("type") != "") {
searchListMineRequest.setType(parameters.get("type").toString());
}
SearchListResponse response = searchListMineRequest.execute();
是产生问题的execute命令。用户在程序的另一部分中使用OAuth进行连接,并且刷新令牌被存储以与上述代码一起使用。我是Google API的新手,所以如果我弄错了一些代码,请找个借口。我收到403错误。但是,由于代码在取消凭证之前就已经起作用,所以我认为问题出在新凭证上。
我收到以下错误消息:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Access Not Configured. YouTube Data API has not been used in project XXXXXXXXXX before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=XXXXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"reason" : "accessNotConfigured",
"extendedHelp" : "https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=XXXXXXXXXXXXX"
} ],
"message" : "Access Not Configured. YouTube Data API has not been used in project X before or it is disabled. Enable it by visiting.......
}
答案 0 :(得分:0)
我找到了解决方案。一旦项目凭证达到90天,我的Google控制台项目就不再是正常运行的项目。有些事情会奏效,有些则行不通。我必须完全删除该项目,再次连接youtube数据API并颁发新的凭据。这样就解决了问题。