Question

I tried to use the google apps reseller api with google apps script. To use oauth I need the AuthServiceName. what is the right name? "apps" does not work.

Était-ce utile?

La solution

AuthServiceName is defined in your application, its not dependent on the API that you are connecting to, i would suspect that you may not have completed all the steps necessary or that your oauth call is not properly structured.

Here is an example of a call that retrieves the details of domains.

function getCustomer() {
  //set up oauth for Google Reseller API
  var oAuthConfig1 = UrlFetchApp.addOAuthService("doesNotMatter");
  oAuthConfig1.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/apps.order.readonly");
  oAuthConfig1.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig1.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=https://script.google.com/a/macros");
  oAuthConfig1.setConsumerKey(CONSUMER_KEY);
  oAuthConfig1.setConsumerSecret(CONSUMER_SECRET);

  var options1 = {oAuthServiceName:"doesNotMatter", oAuthUseToken:"always", 
                  method:"GET", headers:{"GData-Version":"3.0"}, contentType:"application/x-www-form-urlencoded"};

  //set up user profiles url
  var theUrl = "https://www.googleapis.com/apps/reseller/v1/customers/somedomain.com";  

  //urlFetch for customer list
  var customerInfo = "";

  try {
    var response = UrlFetchApp.fetch(theUrl,options1);
    customerInfo = response.getContentText();
  } catch(problem) {
    Logger.log(problem.message);  
  }

  Logger.log(customerInfo);

}

This will work if

  1. You have a reseller account (I guess i.e. I did not test on my non reseller account)
  2. You have create a project in the API console, and enabled the Reseller API
  3. You know your SECRET and KEY lifted form the console
  4. I have use a read.only scope which is safe, if not you need to set up your tests in the sand box

Let me know if you need any more clarifications

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top