2013-03-28 142 views

回答

1

我建議閱讀本post,幫助我來配置和與Android連接到谷歌驅動

編輯:

我有同樣的500錯誤的服務器,以避免出現此錯誤谷歌建議Exponential backoff那根據它們:

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.

實施例:

的Android代碼:

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(); 
     } 
     } 
    } 

} 

我已經測試此代碼,並在最後嘗試連接成功

谷歌推薦使用指數回退與4XX和5XX服務器error

4xx server錯誤主要用於認證問題

相關問題