0

上下文:Windows 7、IE10、JScript、Google Adwords、OAuth2

我使用 urn:ietf:wg:oauth:2.0:oob 技术生成了一个 access_token 和一个 refresh_token ,一切似乎都很好。我以这种方式生成的令牌在 Analytics 调用中运行良好。此问题与对https://adwords.google.com/api/adwords/reportdownload/v201309的 Adwords 调用有关。头部和数据如下:

Authorization: GoogleLogin auth=ya29.blahblah
developerToken: blahblah
clientCustomerId: blahblah
returnMoneyInMicros: false
Content-Type: application/x-www-form-urlencoded

__rdxml=<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201309"> <selector> <fields>CampaignId</fields> <fields>Id</fields> <fields>Impressions</fields> <fields>Clicks</fields> <fields>Cost</fields> <predicates> <field>Status</field> <operator>IN</operator> <values>ENABLED</values> <values>PAUSED</values> </predicates> </selector> <reportName>Custom Adgroup Performance Report</reportName> <reportType>ADGROUP_PERFORMANCE_REPORT</reportType> <dateRangeType>LAST_7_DAYS</dateRangeType> <downloadFormat>CSV</downloadFormat> </reportDefinition>

报告 XML 直接来自文档。

当我提交该请求时,我收到以下错误:

AuthenticationError.GOOGLE_ACCOUNT_COOKIE_INVALID

之后

我改变了标题

Authorization: GoogleLogin auth=ya29.blahblah

Authorization: Bearer ya29.blahblah

我现在得到

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<reportDownloadError>
<ApiError>
<type>AuthenticationError.OAUTH_TOKEN_INVALID</type>
<trigger>&lt;null&gt;</trigger>
<fieldPath></fieldPath>
</ApiError>
</reportDownloadError>

但是,令牌是最新的,在测试之前已重新生成。

最后

将范围更改为

https://adwords.google.com/api/adwords/

也称为非 MCC 帐户。

对于 Mikeys4u

function OAuthConnect(client_id, scope, login_hint) {
  var url = XMAP("https://accounts.google.com/o/oauth2/auth?[1]&[2]&[3]&[4]&[5]&[6]",
      "response_type=code",
      "client_id=" + client_id,
      "redirect_uri=" + "urn:ietf:wg:oauth:2.0:oob",
      "scope=" + escape(scope),
      "state=acit",
      "login_hint=" + login_hint);

  var oIE = new ActiveXObject("InternetExplorer.Application");
  oIE.Visible = true;
  oIE.Navigate(url);
  while (oIE.busy) {
    WScript.Sleep(10);
  };
  var status = oIE.Document.title;
  while (status.indexOf("state=acit") === -1) {
    WScript.Sleep(100);
    status = oIE.Document.title;
  }
  // WScript.Echo(status);
  oIE.Quit();
  var code = RightOf(status, "&code=");
  return code;
}

这指的是很多帮助代码(如 XMAP 和 RightOf),但您应该能够理解。

该代码的调用看起来像

if (accessToken === "") {
  code = OAuthConnect(secrets.client_id, oCFG.retrieve(client + ".scope"), oCFG.retrieve(client + ".login_hint"));

顺便说一下,这是 JScript。

4

0 回答 0