1

I'm creating an Android app that uses a regular Google Drive account as an application-owned account as described, with incredible brevity, here:

Use regular Google accounts as application-owned accounts

Unfortunately all the descriptions of how to do anything on Drive refer to a client secret, and as described here:

Google APIs Console - missing client secret

that doesn't really exist any more for installed apps. I managed to get an OAuth2 token, at incredible pains, by building an actual web page. From this I obtained an access token and a refresh token, as described in the first link. I want to make a GoogleCredential object with these, and as far as I can see this should work like this:

    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(httpTransport)
    .setJsonFactory(jsonFactory)
    .setClientSecrets(
            new GoogleClientSecrets().setInstalled(
                    new Details()
                    .setAuthUri(AUTH_URI)
                    .setClientId(CLIENT_ID)
                    //.setClientSecret("but I haven't got one!")
                    .setRedirectUris(REDIRECT_URIS)
            )
    )
    .build()
    .setAccessToken(ACCESS_TOKEN) //defined above
    .setRefreshToken(REFRESH_TOKEN); //defined above
    Drive.Builder driveBuilder = new Drive.Builder(httpTransport, jsonFactory, null);
    driveBuilder.setHttpRequestInitializer(credential);

I've put in the setClientSecret(...) call as commented out, because I don't have a client secret for the installed application.

Basically, I can't make this credential, and every suggestion about making credentials I have seen falls into one of these three categories:

  1. designed for users to log into their own account. Not acceptable; I want one Drive account for all users BUT a regular account, not a service account (the client specified).
  2. based on AccountManager or some other system of authentication. Not acceptable for the same reason.
  3. throws up its hands in horror at the egregiousness of the Google API. Suggests making the request the old-fashioned way.

By the way, without the client secret set, I get a NullPointerException in Preconditions.class. It doesn't tell me a lot about this. I also tried to make a GoogleCredential directly by subclassing it, and it instructed me to use a GoogleCredential.Builder, which is why I find myself here.

What do I do to get round this client secret problem?

Community
  • 1
  • 1
Andrew Wyld
  • 7,133
  • 7
  • 54
  • 96

2 Answers2

0

The answer seems to be to uncomment the line. The GoogleCredential.Builder succeeds in constructing a credential object as long as something is in the client secret field. But does it actually get the drive? Stick around.

EDIT: no, I'm getting an "invalid_client" error. This is intensely frustrating.

Andrew Wyld
  • 7,133
  • 7
  • 54
  • 96
0

Here's a link to a question that provides its own answer in an edit, using the help of the accepted answer:

How setup Google Drive Credentials within Android App?

In short, the main thing is that you need to get a simple api access key from the developer api console. If you can't find it, then drive api access probably needs to be set.

Community
  • 1
  • 1
Jag
  • 1,840
  • 1
  • 17
  • 25
  • How do you set drive API access? – Andrew Wyld Mar 17 '14 at 11:42
  • Go to: https://console.developers.google.com/project, click your project name, then click APIs & Auth in the menu on the left. A big list of APIs should be visible on the right side now (e.g. Big Query API, Youtube API). Look for "Drive API". – Jag Mar 17 '14 at 12:30
  • Thanks! I'm probably not going to get a chance to look at this for some time (as we eventually switched to having a machine-only drive, with which we *shared* files from another human-readable drive) but this is really good to know. – Andrew Wyld Mar 17 '14 at 13:41