After weeks of struggling with the documentation and plenty of forums I found out how to use both the Drive API Client Library for Java and Google Sheets API. I feel that the documentation especially for android is very lacking so I thought it would be useful to make a post explaining how to import the API's for Android. This is the post I wish I could have found when I started with these two libraries, I hope this helps someone who might have run into my problems..
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Note: this is for Android only, and directed for Android Studio. The configuration descirbed below is what i am using, although there may be some unnecessary files included it does nonetheless work.
So first, the functionality that importing these two APIS will give is access to a users Google Drive, and to edit Google Spreadsheets on that account. There are two "versions" of the Drive API for Android, one made specifically for Android and another for any Java environment. Although the one made specifically for Android is simpler to use and is better integrated with Android it has one major drawback.
Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.
This means your app can only access and edit files it has itself created, for this reason i chose to use the Google APIs Java Client. As for the Google Sheets API there are no real alternative versions, just itself.
Now the hardest time i had was trying to find out which files i needed to import, the documentation on this is hazey so here are the files needed.
Put all these files in the
app\libs
directory of your app.To use Drive API Client Library for Java
First "Download the Drive API v2 Client Library for Java." In
readme.html
it describes what dependencies are needed for android.Use the following jars.
Also include
google-api-services-drive-v2-rev161-1.19.1.jar
To use Google Sheets API version 3.0
Download gdata library from here, this includes spreadhseet jars and other gdata libraries like maps, finance, docs, calendar, etc..
In the gdata\java\lib use the following files.
Download javamail, this is made specifically for android`
Now that you have all these in your app\lib directory your build.gradle should include the following(add these in yourself):`
Final step!
Because of the sheer number of methods that these imported jars have we need to make our app multi-dexable, this process is very straight forward and is described here.Once you've done this your all set to start using the Drive and Spreadsheets API, if you found this useful up vote so other can see!