1
votes

I used YouTube Data API to enable a web-based client I produced for a customer to connect to youtube and list out the videos on her account. This was working fine until the customer left those services unused for 90 days after which the credential was canceled.

I created a new credential but now it doesn't work and I can't figure out the solution. The client authorizes using OAuth then does a 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();

It is the execute command that produces the problem. The user connects using OAuth in another part of the program and the refresh token is stored for use with the above code. I am new to the google api so excuse if I'm getting some code wrong. I am getting a 403 error. However since the code worked before the credential was cancelled, then I conclude that the problem is with the new credential.

I get the following error message:

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.......
}
1

1 Answers

0
votes

I found the solution. Once the project credential reached 90 days, my google console project was no longer a functioning project. Some things would work, others not. I had to completely delete the project, connect the youtube data API again and issue a new credential. This resolved the problem.