use*_*913 4 google-apps-script
我需要一种方法,使用Google Apps脚本将字符串的一部分替换为另一个字符串.我测试了以下内容并且它有效:
function test(){
var value = 'https://plus.google.com/117520727894266469000';
var googleimageURL = googlePlus(value);
Logger.log('Returned Result: ' + googleimageURL);
}
function googlePlus(value){
var apiKey = ScriptProperties.getProperty('apiKey');
var re = 'http://'
var theURL = value;
Logger.log('Google+ is called: ' + value);
var replacingItem = 'https://';
var theURL = theURL.replace(re, replacingItem);
Logger.log('Google+ Values 2: ' + value + ' : ' + theURL + ' after ' + replacingItem);
return imageURL;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我嵌入以下代码时,它无法正常工作.任何的想法?
//If a Google+ column was not specified,put a flag.
if (googleColumn && column == googleColumn) {
if (value == ""){
columns.push(nogoogleColumn);
values.push(flag);
var googleimageURL="";
} else {
var googleimageURL = googlePlus(value);
Logger.log('Returned Result: ' + googleimageURL);
}
}
Run Code Online (Sandbox Code Playgroud)
脚本没有按照我的意愿工作.它似乎停在了一线:
var theURL = theURL.replace(re, replacingItem);
Run Code Online (Sandbox Code Playgroud)
其他信息:Google通知我以下消息
Details:
Start Function Error Message Trigger End
1/30/13 6:51 AM onFormSubmit TypeError: Cannot find function replace in object https://plus.google.com/117520727894266469000. (line 536) formSubmit 1/30/13 6:51 AM
Run Code Online (Sandbox Code Playgroud)
我发现了错误.这是类型错误.第二个块中的"value"不是"string",而第一个块是"string".因此要修复第二个块,我需要使用
var value = value.toString();
在传递给googlePlus(值)之前
rgds,aa
| 归档时间: |
|
| 查看次数: |
4632 次 |
| 最近记录: |