在加載在瀏覽器中如何使用Google Apps腳本通過USPS API獲得國內運費?
Link: http://production.shippingapis.com/ShippingAPITest.dll?API=RateV4&XML=<RateV4Request USERID="[userid]"><Revision/><Package ID="1ST"><Service>PRIORITY</Service><ZipOrigination>02211</ZipOrigination><ZipDestination>90210</ZipDestination><Pounds>5</Pounds><Ounces>2</Ounces><Container>RECTANGULAR</Container><Size>LARGE</Size><Width>15</Width><Length>30</Length><Height>15</Height><Girth>55</Girth></Package></RateV4Request>
我用正確的結果(如下圖)返回
<RateV4Response>
<Package ID="1ST">
<ZipOrigination>02211</ZipOrigination>
<ZipDestination>90210</ZipDestination>
<Pounds>5</Pounds>
<Ounces>2</Ounces>
<Container>RECTANGULAR</Container>
<Size>LARGE</Size>
<Width>15</Width>
<Length>30</Length>
<Height>15</Height>
<Zone>8</Zone>
<Postage CLASSID="1">
<MailService>Priority Mail 2-Day<sup>™</sup></MailService>
<Rate>86.65</Rate>
</Postage>
</Package>
</RateV4Response>
這個環節,它是由關於封裝通過美國郵政和細節所提供的用戶ID,但是,嘗試使用以下代碼塊從Google Apps腳本編輯器中的某個功能加載API時:
function xmlLoader(){
var pounds = 5;
var ounces = 2;
var userid = "[userid]";
var url = "http://production.shippingapis.com/ShippingAPI.dll";
var options =
{
"API" : "RateV4",
"XML" : "<RateV4Request USERID=\"" + userid + "\"> \
<Revision/> \
<Package ID=\"1ST\"> \
<Service>PRIORITY</Service> \
<ZipOrigination>02211</ZipOrigination> \
<ZipDestination>90210</ZipDestination> \
<Pounds>" + pounds + "</Pounds> \
<Ounces>" + ounces + "</Ounces> \
<Container>RECTANGULAR</Container> \
<Size>LARGE</Size> \
<Width>15</Width> \
<Length>30</Length> \
<Height>15</Height> \
<Girth>55</Girth> \
</Package> \
</RateV4Request>"
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
};
This i就是我正與返回的錯誤,
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Number>80040B19</Number>
<Description>XML Syntax Error: Please check the XML request to see if it can be parsed.</Description>
<Source>USPSCOM::DoAuth</Source>
</Error>
任何援助將不勝感激
請注意,SO是一個國際性論壇,如果您不說明您是來自哪個國家,我們不知道您的意思是「國內」。 (哦,我想「USPS」可能會提供一些線索 - 例如美國郵政服務或美國包裹服務,或許?) –
您的評論讓我很好奇,是否存在我指的是哪個國家/地區的標識符,這是美國。最明確的辦法是在域名I上鍊接[shippingapis.com](http://www.shippingapis.com),向您提供所有者的姓名,地址,電話號碼和電子郵件。 – user1371414