java - AuthError On YouTube Search List Execute -
i exploring youtube api , creating java application can search authorized users token. authorization follows.
private static credential authorize(string storedirectory) throws exception { // load client secrets yt.data_store_dir = new java.io.file(".",".store/"+storedirectory); yt.datastorefactory = new filedatastorefactory(yt.data_store_dir); googleclientsecrets clientsecrets = googleclientsecrets.load(yt.json_factory, new inputstreamreader(new bytearrayinputstream(yt.client_secret_json.getbytes(standardcharsets.utf_8)))); if (clientsecrets.getdetails().getclientid().startswith("enter") || clientsecrets.getdetails().getclientsecret().startswith("enter ")) { system.out.println( "enter client id , secret https://code.google.com/apis/console/?api=plus " + "into client string."); system.exit(1); } string[] permissoins = { plusscopes.plus_login, plusscopes.plus_me, plusscopes.userinfo_email, plusscopes.userinfo_profile, "https://www.googleapis.com/auth/youtube" }; // set authorization code flow googleauthorizationcodeflow flow = new googleauthorizationcodeflow.builder( yt.httptransport, yt.json_factory, clientsecrets, new arraylist(arrays.aslist(permissoins))).setdatastorefactory( yt.datastorefactory).build(); // authorize return new authorizationcodeinstalledapp(flow, new localserverreceiver()).authorize("user"); }
i trying search single keyword bellow
credential credential = authorize("username"); youtube.search.list search = youtube.search().list("id,snippet"); // have set oauthtoken here. search.setoauthtoken(credential.getaccesstoken()); search.setmaxresults(50l); search.setq("search keyword"); search.settype("video"); search.setfields("items(id/kind,id/videoid,snippet/title,snippet/thumbnails/default/url)"); // exception below line. searchlistresponse searchresponse = search.execute(); list<searchresult> searchresultlist = searchresponse.getitems();
i getting exception details below.
ex = (com.google.api.client.googleapis.json.googlejsonresponseexception) com.google.api.client.googleapis.json.googlejsonresponseexception: 401 unauthorized { "code" : 401, "errors" : [ { "domain" : "global", "location" : "authorization", "locationtype" : "header", "message" : "invalid credentials", "reason" : "autherror" } ], "message" : "invalid credentials" }
i wondering missing set api key or else wrong.
do need use
search.setkey("youtube_developer_key");
i confused use youtube_developer_key
?
Comments
Post a Comment