我正在尝试创建一个Google Apps脚本,删除上传到GA的旧文件,然后上传当前的文件。
上传行和列出上传的行很有效:
import functools
import tkinter as tk
import tkinter.ttk as ttk
import re
class App(ttk.Frame):
def __init__(self, parent=None, *args, **kwargs):
ttk.Frame.__init__(self, parent, style='self.TFrame')
self.style=ttk.Style()
self.style.configure('self.TFrame', background='pink', borderwidth=10,
relief='raised')
self.pwstrength = tk.StringVar()
label = ttk.Label(self, text="Password: ")
# vcmd = (self.register(self._passwordStrength), '%P')
valcommand = self.register(
functools.partial(App._passwordStrength, self.pwstrength)
)
vcmd = (valcommand, '%P')
ePassword = ttk.Entry(self, validate="key", validatecommand=vcmd)
warnLabel = ttk.Label(self, textvariable=self.pwstrength)
label.grid(row=0, column=0, sticky='w', padx=20, pady=20)
ePassword.grid(row=0, column=1, sticky='w')
warnLabel.grid(row=1, column=1, sticky='w')
@staticmethod
def _passwordStrength(svar, P):
'''Check password strength.
A password is considered strong if:
8 characters length or more
1 digit or more
1 symbol or more
1 uppercase letter or more
1 lowercase letter or more'''
password = P
print (password, len(password))
# check length
if password == '':
svar.set('')
return True
# check length
if len(password) < 8:
svar.set('Password is too short')
return True
# check for digits
if not re.search(r"\d", password):
svar.set('Password missing a number.')
return True
# check for uppercase
if not re.search(r"[A-Z]", password):
svar.set('Password missing upper case letter.')
return True
# check for lowercase
if not re.search(r"[a-z]", password):
svar.set('Password missing lower case letter.')
return True
# check for symbols
if not re.search(r"\W", password):
svar.set('Password missing a symbol.')
return True
# Passed all checks.
svar.set('Strong password provided.')
return True
if __name__=='__main__':
root = tk.Tk()
root.geometry('300x300+700+250')
root.title('Password Strength Check')
app=App(root)
app.grid(row=0, column=0, sticky='nsew')
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.mainloop()
但是,我无法使上传删除工作。我尝试以下代码:
var upload = Analytics.Management.Uploads.uploadData(accountId, webPropertyId, customDataSourceId, blobData);
var request = Analytics.Management.Uploads.list(accountId, webPropertyId, customDataSourceId)
我收到错误:
GoogleJsonResponseException:无效值'UA-xxxxxxxx-x'。值必须与以下正则表达式匹配:'\ d +'。
似乎脚本试图使用属性ID作为帐户ID,所以我尝试了另一种方法:
for (var k = 0; k <= request["items"].length - 1; k++) {
var customDataImportUid = request["items"][k]["id"]; //get the unique upload id
//delete the file with a specific upload id:
var deleteUpload = Analytics.Management.Uploads.deleteUploadData(
accountId, webPropertyId, customDataSourceId, customDataImportUid);
}
然后得到错误:
异常:额外的args块必须是javascript对象文字。
两个问题:
答案 0 :(得分:1)
您的请求失败的原因是您的请求不正确:
如果我使用脚本编辑器开始编写自己的函数,我会得到以下方法签名:
因此,该函数的第一个参数不应该是0
或accountId
。它需要是请求资源。
从documentation开始,应该是这样的:
{
'customDataImportUids': ['AAABBBCCCDDD111222',
'xLh4wXtzQT6uxe-_OWelog']
}
您的用法是将此参数作为最后一个参数,而不是第一个参数
请注意,该方法不会返回任何内容,因此您的变量deleteUpload
将是未定义的。重写,这变为:
myCustomDataImportUids = [];
for(var k = 0; k < request.items.length; ++k) {
myCustomDataImportUids.push(request.items[k].id);
}
// Delete them.
Analytics.Management.Uploads.deleteUploadData(
{customDataImportUids: myCustomDataImportUids},
accountId, webPropertyId, customDataSourceId
);