Use Adwords API (MccApp) in Google Apps Script

好久不见. 提交于 2021-02-07 04:19:30

问题


I have a custom API written in GAS (Google Apps Script) and would like to utilize the Adwords API from within it.

Sometimes used along with the MccApp, the service is readily available from within Adwords Scripts itself (My Client Center > Scripts).

For Example:

            function account(client) {
              var result = {
                  'id': null,
                  'campaigns': {}
              }
              result.id = client.getCustomerId()
              var currentAct = AdWordsApp.currentAccount()
              MccApp.select(client)
              var campaignIterator = AdWordsApp.campaigns().get()
              while (campaignIterator.hasNext()) {
                  var campaign = campaignIterator.next()
                  result.campaigns[campaign.getName()] = campaign.getId()
              }
              MccApp.select(currentAct)
              return result
            }

However, this API is not readily available inside a Google Apps Script. I have tried enabling it under "Resources > Advanced Google Services" and also under the developer console, but the UI offers no option that I can see.

QUESTION: Is it possible to enable use of the AdwordsApp and MccApp inside a Google Apps script so that the above code snippet would work in GAS?

If not, I understand already there are two workarounds:

  1. Just use Adwords Script

  2. Communicate with the API from GAS as though it were an external service (i.e... using SOAP, REST, etc...)


回答1:


After much research, there really is no way to add the MccApp and AdwordsApp services for use in a Google Apps script. The nearest solution is to communicate with the API as though it were external or just use an Adwords Script.




回答2:


It looks like you might be able to get to the AdWord API through the Management API:

See the Conceptual Overview section:

AdWords Links can be constructed at the Web Property level.

Google Developer Guide - What Is The Management API - Overview

and you can get to the Management API with the Google Analytics API.

Quote:

The Analytics service allows you to use the Google Analytics Management API and Reporting APIs in Apps Script

Google Documentation - Google Analytics API

So, you need to use the RESOURCES menu, Choose, ADVANCED GOOGLE SERVICES, and then turn the Google Analytics API on.

With the Google Analytics API, you can access the Management API.



来源:https://stackoverflow.com/questions/28030902/use-adwords-api-mccapp-in-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!