Google Drive/OAuth - Can't figure out how to get re-usable GoogleCredentials

前端 未结 3 2282
無奈伤痛
無奈伤痛 2021-02-20 05:51

I\'ve successfully installed and run the Google Drive Quick Start application called DriveCommandLine. I\'ve also adapted it a little to GET file info for one of the files in my

3条回答
  •  遥遥无期
    2021-02-20 06:19

    Oath2Scopes is imported as follows:

    import com.google.api.services.oauth2.Oauth2Scopes;
    

    You need to have the jar file 'google-api-services-oauth2-v2-rev15-1.8.0-beta.jar' in your class path to access that package. It can be downloaded here.

    No, I don't know how to get Credentials without having to visit the authorization URL at least once and copy the code. I've modified MyClass to store and retrieve credentials from a database (in my case, it's a simple table that contains userid, accesstoken and refreshtoken). This way I only have to get the authorization code once and once I get the access/refresh tokens, I can reuse them to make a GoogleCredential object. Here's how Imake the GoogleCredential object:

    GoogleCredential credential = new GoogleCredential.Builder().setJsonFactory(jsonFactory)
                .setTransport(httpTransport).setClientSecrets(clientid, clientsecret).build();
        credential.setAccessToken(accessToken);
        credential.setRefreshToken(refreshToken);
    

    Just enter your clientid, clientsecret, accessToken and refreshToken above.

    I don't really have a whole lot of time to separate and tidy up my entire code to post it up here but if you're still having problems, let me know and I'll see what I can do. Although, you are effectively asking a blind man for directions. My understanding of this whole system is very sketchy!

    Cheers, Brian

提交回复
热议问题