title: Google Drive API webContentLink redirects to a different domain
body: <p>I am using the Google Drive API to access files on my team drive.  My server application uses OAuth2 to obtain an access token.  I then use this token as a Bearer token to make API drive calls.  When I am trying to download an image from my team drive, one of the files listed when calling the <a href="https://www.googleapis.com/drive/v3/files" rel="nofollow noreferrer">https://www.googleapis.com/drive/v3/files</a> endpoint is:</p>
  
  <p><code>{
    "id": "&lt;longAlphaNumericID&gt;",
    "mimeType": "image/jpeg",
    "webContentLink": "https://drive.google.com/a/&lt;myTeamDriveDomain&gt;/uc?id=SOME_GOOGLE_DRIVE_ID&amp;export=download",
    "fileExtension": "jpg",
    "size": "108794"
   }</code></p>
  
  <p>When I try to download the webContentLink with the same Bearer token in the request headers, I am redirected to <a href="https://doc-0k-08-docs.googleusercontent.com/docs/securesc/" rel="nofollow noreferrer">https://doc-0k-08-docs.googleusercontent.com/docs/securesc/</a>...</p>
  
  <p>The Bearer token doesn't seem to work for this googleusercontent.com domain, and my server is eventually forwarded on to a sign in page (which is not good for a server app).</p>
  
  <p>When trying to make this second request, I noticed the response headers contains:</p>
  
  <p><code>Access-Control-Allow-Origin: *
  Access-Control-Allow-Credentials: false
  Access-Control-Allow-Methods: GET,OPTIONS
  P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/answer/151657?hl=en for more info."</code></p>
  
  <p>I assume this last header is pointing me to the problem, and it has something to do with the redirect going to a different domain, but I'm not sure what I need to do about it.  I thought the access token granted through OAuth2 with the proper scope should allow me to do everything.  It does seem to work for everything else (accessing spreadsheets, documents, etc.), but I am having difficulty downloading images in this way.</p>
  
  <p>Here is a detailed list of requests and responses:</p>
  
  <ol>
  <li>Request: OAuth2 call to get access token with my client id and secret.</li>
  <li>Response: Received the access token.  Good</li>
  <li>Request: <code>https://www.googleapis.com/drive/v3/files?corpora=teamDrive&amp;includeTeamDriveItems=true&amp;supportsTeamDrives=true&amp;teamDriveId=[myTeamDriveID]</code> with Authorization token in header.</li>
  <li>Response.  Status 200.  Received file list.  Awesome.</li>
  <li>For each image, request the webContentLink with the Authorization token in header</li>
  <li>Request: <code>https://drive.google.com/a/[myTeamDriveDomain]/uc?id=[fileID]&amp;export=download</code></li>
  <li>Response: Status 302 with P3P header <code>CP="This is not a P3P policy!</code> Redirected to <code>http://docs.google.com/a/[myTeamDriveDomain]/nonceSigner?nonce=[alphaNumericID]&amp;continue=https://doc-0g-08-docs.googleusercontent.com/docs/securesc/[longAlphaNumericID]/[longAlphaNumericID]/[longNumericID]/[longNumericID]/[longNumericID]/[longAlphaNumericID]?e%3Ddownload%26h%3D[longNumericID]&amp;hash=[hashValue]</code></li>
  <li>Request: Get redirect url from previous response with Authorization token in header</li>
  <li>Response: Status 302.  Redirected to <code>https://www.google.com/a/]myTeamDriveDomain]/ServiceLogin?passive=1209600&amp;osid=1&amp;continue=[previousRedirectURL]&amp;followup=[previousRedirectURL]</code></li>
  <li>Request: Get redirect url from previous response with Authorization token in header</li>
  <li>Response: Status 200.  This is the login page.  While debugging, if I enter my credentials I will get the image, but the server can't do this.  It needs to be able to use Access tokens</li>
  </ol>
  
  <p>Any ideas what I'm doing wrong?</p>