上下文:Windows 7,IE10,JScript,Google Adwords,OAuth2
我使用urn生成了一个access_token和一个refresh_token:ietf:wg:oauth:2.0:oob技术,所有似乎都没问题。我用这种方式生成的令牌在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
LATER
我更改了标题
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><null></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。