【问题标题】:whar is the oauth service name for the google apps reseller apiwhar 是 google apps reseller api 的 oauth 服务名称
【发布时间】:2013-09-18 16:10:01
【问题描述】:

我尝试将谷歌应用程序经销商 API 与谷歌应用程序脚本一起使用。要使用 oauth,我需要 AuthServiceName。什么是正确的名字? “应用程序”不起作用。

【问题讨论】:

    标签: oauth google-apps-script google-reseller-api service-name


    【解决方案1】:

    AuthServiceName 是在您的应用程序中定义的,它不依赖于您要连接的 API,我怀疑您可能没有完成所有必要的步骤,或者您的 oauth 调用结构不正确。

    这是一个检索域详细信息的调用示例。

    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);
    
    }
    

    如果

    1. 您有一个经销商帐户(我猜是我没有在我的非经销商帐户上进行测试)
    2. 您已在 API 控制台中创建了一个项目,并启用了 Reseller API
    3. 您知道您的 SECRET 和 KEY 从控制台中提取的
    4. 我使用了一个安全的只读范围,如果不是,您需要在沙盒中设置测试

    如果您需要更多说明,请告诉我

    【讨论】:

    • 非常感谢。我尝试使用“匿名”作为秘密和密钥,并得到“usageLimits”错误。所以使用特定的秘密和密钥似乎更好。如何在 concole 中获得一个?我应该获取域密钥和秘密吗?如何获得钥匙?
    • 您需要了解的有关 API 控制台的一切都在这里:developers.google.com/console/help
    • 非常感谢...我在您的脚本代码中使用了我的密钥和密钥并收到此错误:错误值 oAuthServiceName ...
    猜你喜欢
    • 1970-01-01
    • 2018-10-06
    • 2022-11-21
    • 2013-04-28
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    相关资源
    最近更新 更多