googleworkspace / android-samples

Android samples for Google Workspace APIs
Apache License 2.0
635 stars 410 forks source link

Question: need more understanding of how to run the sample app #46

Closed AndroidDeveloperLB closed 6 years ago

AndroidDeveloperLB commented 8 years ago

This is what's written on the repo's page:

If you actually want to run this sample app (though it is mostly provided so you can read the code), you will need to register an OAuth 2.0 client for the package com.google.android.gms.drive.sample.demo with your own debug keys and set any resource IDs to those that you have access to. Resource ID definitions are on:

com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FOLDER_ID com.google.android.gms.drive.sample.demo.BaseDemoActivity.EXISTING_FILE_ID

What I don't understand:

  1. How do I register the OAuth 2.0 for the package name?
  2. What are the debug keys, where do I get them, and what should I do with them?
  3. What are the resource IDs and where do I get them?
pmk2429 commented 8 years ago

1) In order to use this application, you need to authorize the application(main package) using OAuth 2.0 since this application access Google APIs, Google recommends to authorize the app. More information on the topic can be found here

2) It requires for developers to digitally sign the appp in order to be installed. The signing can be done in debug mode and release mode. Since if you are working on app and need your app to be digitally signed, you can do it in debug mode. Now, signing can be done using Android Studio or via keytool. The Android SDK generates a certificate to sign apps in debugmode. A more detailed explanation of what signing is and why it is useful as well as required can be found here

You can generate SHA1 fingerprint for signing the apps on Google Developer Console using the following command on Windows: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

or

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

After the running the above command in command prompt, a SHA1 fingerprint of your debug.keystore will be produced which act as a signature and this signature is used to sign off your app in Google Dev Console. Remember Keystore is basically a place where the private keys for your app are kept. In simple words its a certificate generated by user or a program, used for signing an Android app.

Next, create credentials appropriate to your project in the Google Developers Console: Open the Credentials page

  1. Click Add credentials > OAuth 2.0 client ID.
  2. Select Android.
  3. In the Package name field, enter your Android app's package name.(The one in AndroidManifest.xml)
  4. Paste the SHA1 fingerprint into the form where requested.
  5. Click Create.

Otherwise, follow the steps below, which are for applications that only need to make unauthorized API calls:

  1. Click Add credentials > API key.
  2. Select Android key.
  3. Paste the SHA1 fingerprint into the form where requested.
  4. Type your Android app's package name into the form where requested.
  5. Click Create.

Here is the tutorial if you want to refer more

3) The ResourceID is the one where all the resources of the application are defined and which you need to specify in order to sign your app on Google Dev Console. In other words, you need path to the package where Ris defined. R is a class containing the definitions for all resources of a particular application package. It is in the namespace of the application package. This step is basically the same step as Step #3 and Step #4 in above mentioned steps

Hope this will help you to get started using the app.