NullPointerException when trying to read .json file - Youtube Java Api -


i trying upload video in youtube java, using youtube's api, error:

throwable: null java.lang.nullpointerexception     @ java.io.reader.<init>(reader.java:78)     @ java.io.inputstreamreader.<init>(inputstreamreader.java:72)     @ youtube.auth.authorize(auth.java:55)     @ youtube.uploadvideo.<init>(uploadvideo.java:61)     @ lyricspro.main.main(main.java:21) 

here .json file:

{   "installed": {       "client_id": "id1234",       "client_secret": "secret123456"   } } 

and here class error occurs:

package youtube;  import com.google.api.client.auth.oauth2.credential; import com.google.api.client.auth.oauth2.storedcredential; import com.google.api.client.extensions.java6.auth.oauth2.authorizationcodeinstalledapp; import com.google.api.client.extensions.jetty.auth.oauth2.localserverreceiver; import com.google.api.client.googleapis.auth.oauth2.googleauthorizationcodeflow; import com.google.api.client.googleapis.auth.oauth2.googleclientsecrets; import com.google.api.client.http.httptransport; import com.google.api.client.http.javanet.nethttptransport; import com.google.api.client.json.jsonfactory; import com.google.api.client.json.jackson2.jacksonfactory; import com.google.api.client.util.store.datastore; import com.google.api.client.util.store.filedatastorefactory;  import java.io.file; import java.io.ioexception; import java.io.inputstreamreader; import java.util.list;  /**  * shared class used every sample. contains methods authorizing user , caching credentials.  */ public class auth {      /**      * define global instance of http transport.      */     public static final httptransport http_transport = new nethttptransport();      /**      * define global instance of json factory.      */     public static final jsonfactory json_factory = new jacksonfactory();      /**      * directory used under user's home directory oauth tokens stored.      */     private static final string credentials_directory = ".oauth-credentials";      /**      * authorizes installed application access user's protected data.      *      * @param scopes              list of scopes needed run youtube upload.      * @param credentialdatastore name of credential datastore cache oauth tokens      */     public static credential authorize(list<string> scopes, string credentialdatastore) throws ioexception {           // load client secrets.         reader clientsecretreader = new inputstreamreader(auth.class.getresourceasstream("client_secrets.json"));         googleclientsecrets clientsecrets = googleclientsecrets.load(json_factory, clientsecretreader);          // checks defaults have been replaced (default = "enter x here").         if (clientsecrets.getdetails().getclientid().startswith("enter")                 || clientsecrets.getdetails().getclientsecret().startswith("enter ")) {             system.out.println(                     "enter client id , secret https://console.developers.google.com/project/_/apiui/credential "                             + "into src/main/resources/client_secrets.json");             system.exit(1);         }          // creates credentials datastore @ ~/.oauth-credentials/${credentialdatastore}         filedatastorefactory filedatastorefactory = new filedatastorefactory(new file(system.getproperty("user.home") + "/" + credentials_directory));         datastore<storedcredential> datastore = filedatastorefactory.getdatastore(credentialdatastore);          googleauthorizationcodeflow flow = new googleauthorizationcodeflow.builder(                 http_transport, json_factory, clientsecrets, scopes).setcredentialdatastore(datastore)                 .build();          // build local server , bind port 8080         localserverreceiver localreceiver = new localserverreceiver.builder().setport(8080).build();          // authorize.         return new authorizationcodeinstalledapp(flow, localreceiver).authorize("user");     } } 

the error occurs in line:

reader clientsecretreader = new inputstreamreader(auth.class.getresourceasstream("client_secrets.json")); 

i have tried place .json file in possible locations inside project folder, can't solve this. suggestions ?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -