title: Google Sign-In server implementation returns 401
body: <p>While trying to switch from the Google+ Sign-In in Play Services 8.1 to the new Google Sign-In in Play Services 8.3, the server side component stops working and starts throwing 401's on every API call to Google servers.</p>
  
  <h2>When the Android app was using Google Play Services 8.1:</h2>
  
  <p><strong>build.gradle:</strong></p>
  
  <pre><code>compile 'com.google.android.gms:play-services-plus:8.1.0'
  </code></pre>
  
  <p><strong>Android client:</strong></p>
  
  <pre><code>mGoogleApiClient = new GoogleApiClient.Builder(this)
           .addApi(Plus.API)
           .addScope(Plus.SCOPE_PLUS_PROFILE)
           .addScope(new Scope("email"))
           .build();
  String scopes = "oauth2:profile email";    
  accessToken = GoogleAuthUtil.getToken(
          SignInActivity.this, 
          Plus.AccountApi.getAccountName(mGoogleApiClient), 
          scopes); // then send accessToken to the server
  </code></pre>
  
  <p><strong>Server side:</strong></p>
  
  <pre><code> // get user details from Google+ REST API
   GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
   Plus plusService = new Plus.Builder(new NetHttpTransport(), new JacksonFactory(), null)
           .setApplicationName("AppName")
           .setHttpRequestInitializer(credential)
           .build();
   Person person = plusService.people().get("me").execute();
  </code></pre>
  
  <h2>When switching to Google Play Services 8.3:</h2>
  
  <p><strong>build.gradle:</strong></p>
  
  <pre><code> compile 'com.google.android.gms:play-services-auth:8.3.0'
  </code></pre>
  
  <p><strong>Android app:</strong></p>
  
  <pre><code>GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
          .requestServerAuthCode("GOOGLE_CLIENT_ID", false)
          .requestEmail()
          .build();
   mGoogleApiClient = new GoogleApiClient.Builder(this)
           .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
           .build();
  </code></pre>
  
  <p>With the same server code, the get("me") call returns:</p>
  
  <pre><code>com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
  {
    "code" : 401,
    "errors" : [ {
      "domain" : "global",
      "location" : "Authorization",
      "locationType" : "header",
      "message" : "Invalid Credentials",
      "reason" : "authError"
    } ],
    "message" : "Invalid Credentials"
  }
  </code></pre>