title: Google Apps Scripts: OAuthConfig to Big Query
body: <p>I'm trying to run a Google Apps Script that will load JSON data into Big Query, and am running into a problem.  </p>
  
  <p>I am actually trying to run this in Adwords Scripts, which are the same as Google Apps Scripts, except they don't have advanced services available, like that of the Big Query Service - so I can't use that.</p>
  
  <p>They do have an OauthConfig service and you can send POST data from AdWords, so I can send data that way, but I am having trouble getting the OAuthConfig service to authenticate first.</p>
  
  <p>Here is what I am running in a Google App Script:</p>
  
  <pre><code>var oAuthConfig = UrlFetchApp.addOAuthService("bigquery");
  oAuthConfig.setAuthorizationUrl('https://accounts.google.com/o/oauth2/auth');
  oAuthConfig.setAccessTokenUrl('https://accounts.google.com/o/oauth2/token');
  oAuthConfig.setRequestTokenUrl('https://accounts.google.com/o/oauth2/token?scope=https://www.googleapis.com/auth/bigquery');
  oAuthConfig.setConsumerSecret(ClientSecret);
  oAuthConfig.setConsumerKey(ConsumerKey );
  </code></pre>
  
  <p>The ConsumerKey and ConsumerSecret are coming from Cloud Console -> APIs &amp; Auth -> Credentials, where I set up a client ID for web application.  The ConsumerKey is set to be the Client ID (something.apps.googleusercontent.com), and the ClientSecret is the Client Secret. Big Query API is enabled for the cloud console project, and I verified that I am able to upload data from other sources.</p>
  
  <p>When I try to execute the following, I keep getting an authentication error:</p>
  
  <pre><code>var config = {
    'method':'post',
    'oAuthServiceName':'bigquery',
    'oAuthUseToken' : "always",
    'muteHttpExceptions':true
  }
  
  var result = UrlFetchApp.fetch('https://www.googleapis.com/upload/bigquery/v2/projects/'+projectName+'/jobs', config);
  </code></pre>
  
  <blockquote>
    <p>"Failed to authenticate for service: bigquery"</p>
  </blockquote>
  
  <p>I understand I should pass data to it in the body, but right now I am just trying to authenticate with the service first.</p>