I recommend read this post that helped me to configure and connect to Google Drive with Android
EDIT:
I had the same 500 error server, to avoid this error Google recommend the Exponential backoff
that according to them:
Exponential backoff is a standard error handling strategy for network
applications in which the client periodically retries a failed request
over an increasing amount of time. If a high volume of requests or
heavy network traffic causes the server to return errors, exponential
backoff may be a good strategy for handling those errors. Conversely,
it is not a relevant strategy for dealing with errors unrelated to
rate-limiting, network volume or response times, such as invalid
authorization credentials or file not found errors.
Used properly, exponential backoff increases the efficiency of
bandwidth usage, reduces the number of requests required to get a
successful response, and maximizes the throughput of requests in
concurrent environments.
Example:
Android code:
FileList files = null;
for (int n = 0; n < 5; ++n) {
try {
setStatus("trying n = " + n);
files = service.files()
.list()
.setMaxResults(1)
.setQ("mimeType = 'application/vnd.google-apps.folder' and title = 'folder_title'")
.execute();
}
catch (GoogleJsonResponseException e)
{
if (e.getDetails().getCode() == 500) {
try {
Thread.sleep((1 << n) * 1000 + randomGenerator.nextInt(1001));
setStatus("sleep() n = " + n);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
setStatus("InterruptedException n = " + n + " " + e1.getMessage());
e1.printStackTrace();
}
}
}
}
I have tested this code and in the last try it connects successfully
Google recommend to use the Exponential backoff with 4xx and 5xx server error
The 4xx server errors are mostly for authentication problem