title: php google ads api - unauthorized_client
body: <p>I'm using 'Google_Client' class to authenticate access to adwords api so:</p>
  
  <pre><code>$REDIRECT_URI = 'http://localhost/GoogleAdwords/auth.php';
  $client = new Google_Client();
  $client-&gt;setApplicationName("App name");
  
  $SCOPES = array('https://www.googleapis.com/auth/adwords'  
        );
    $client-&gt;setIncludeGrantedScopes(true);
    $client-&gt;setAccessType('offline');
    $client-&gt;setRedirectUri($REDIRECT_URI);
    $client-&gt;setScopes($SCOPES);
  
  try{
              $oauth2 = (new OAuth2TokenBuilder())
                      -&gt;withClientId($OAuthCredentials['clientId'])
                      -&gt;withClientSecret($OAuthCredentials['clientSecret'])
                      -&gt;withRefreshToken($client-&gt;getRefreshToken())
                      -&gt;build();
  
              }catch(Exception $err){
          //redirect("auth.php");
                   echo $err;
              }
  </code></pre>
  
  <p>After authentication:</p>
  
  <pre><code>$oauth2 = (new OAuth2TokenBuilder())
                      -&gt;withClientId($OAuthCredentials['clientId'])
                      -&gt;withClientSecret($OAuthCredentials['clientSecret'])
                      -&gt;withRefreshToken($client-&gt;getRefreshToken())
                      -&gt;build();
    $session = (new AdWordsSessionBuilder())
                      -&gt;fromFile()    
                      -&gt;withOAuth2Credential($oauth2)                
                      -&gt;build();
  
  $adWordsServices = new AdWordsServices();
          $managedCustomerService = $adWordsServices-&gt;get($session, ManagedCustomerService::class);
  
  
  
          $selector = new Selector();
          $selector-&gt;setFields(['CustomerId', 'Name']);
          $selector-&gt;setOrdering([new OrderBy('CustomerId')]);
  
  
          try{
          $mccAccounts = $managedCustomerService-&gt;get($selector);
          }catch(Exchange $e){
              // echo $e-&gt;getMessage();
          }
  </code></pre>
  
  <p>I'm pretty sure that the client is authenticated as I can get refreshToken and access token. But I'm getting this error:</p>
  
  <pre><code> Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response: { "error": "unauthorized_client", "error_description": "Unauthorized" } 
  </code></pre>
  
  <p>What could be the problem here? Am I missing something?</p>
  
  <p>EDIT:</p>
  
  <p>Using the same $client to access user information and shopping content works fine, but that's not the case for adwords.</p>