回答自己:
通过正常机制向OAuth认证,即在JS中:
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'https://domain_for_your_api/',
'app_name': 'Your app name'
});
然后验证并运行您的 SOAP 请求作为回调:
function authenticateAndGetAlerts() {
oauth.authorize(runMyRequest);
}
SOAP 标头是所记录内容的较小版本,省略了仅对 ClientLogin API 必需的字段。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://adwords.google.com/api/adwords/mcm/v201008" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201008" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<ns1:RequestHeader xsi:type="ns2:RequestHeader">
<ns2:developerToken>Your developer token</ns2:developerToken>
<ns2:userAgent>Your app name</ns2:userAgent>
</ns1:RequestHeader>
</SOAP-ENV:Header>
身体正常。
然后使用适当的方法(JS 中的 oauth.sendSignedRequest)发布此内容,该方法会将所需的 OAuth 字段添加到查询字符串中:
var request = {
'method': 'POST',
'body': soapenvelope
};
oauth.sendSignedRequest(url, callback, request);
完成。如果您需要手动进行查询而不是使用 sendSignedRequest 之类的东西,它看起来像:
servicename.google.com/where/your/service/lives?oauth_consumer_key=anonymous&oauth_nonce=something&oauth_signature=something&oauth_signature_method=HMAC-SHA1&oauth_timestamp=something&oauth_token=something
TLDR:查询字符串中的 OAuth,省略 SOAP 标头中的所有身份验证信息。