Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GoogleAppClient-Python中使用静态变量而不是argparse_Python_Google Search Api - Fatal编程技术网

在GoogleAppClient-Python中使用静态变量而不是argparse

在GoogleAppClient-Python中使用静态变量而不是argparse,python,google-search-api,Python,Google Search Api,我刚刚开始使用Google Search Analytics API main for python 我想更进一步,将静态变量传递给sample_tools.init(),而不是在命令行界面中要求它们 我可以用哪种方式添加这些参数并传递给示例_tools.init() 开始日期='2015-10-20'开始日期='2015-10-21'变量uri= '' 这很简单,我只是从数组中删除了argparser,并将其保留为空,然后定义变量 def main(argv): service, fl

我刚刚开始使用Google Search Analytics API main for python

我想更进一步,将静态变量传递给sample_tools.init(),而不是在命令行界面中要求它们

我可以用哪种方式添加这些参数并传递给示例_tools.init()

开始日期='2015-10-20'开始日期='2015-10-21'变量uri= ''


这很简单,我只是从数组中删除了argparser,并将其保留为空,然后定义变量

def main(argv):
    service, flags = sample_tools.init(
        argv, 'webmasters', 'v3', __doc__, __file__, parents=[],
        scope='https://www.googleapis.com/auth/webmasters.readonly')

    start_date = datetime.datetime.strftime(
        datetime.datetime.now() - datetime.timedelta(days=4), '%Y-%m-%d')
    end_date = datetime.datetime.strftime(
        datetime.datetime.now() - datetime.timedelta(days=3), '%Y-%m-%d')

    property_uri = 'http://www.bmimedia.net'

    #Create the request. Use the API tutorial to explain how the API works
    request = {
        'startDate': end_date,
        'endDate': end_date,
        'dimensions': ['page', 'query'],
        'rowLimit': 10
    }

    response = execute_request(service, property_uri, request)
    print_table(response, 'Top Queries', end_date)

甚至
argv
也可以被
[]
替换,并且可以从
sample\u tools.init
args中删除
parents=[]
def main(argv):
    service, flags = sample_tools.init(
        argv, 'webmasters', 'v3', __doc__, __file__, parents=[],
        scope='https://www.googleapis.com/auth/webmasters.readonly')

    start_date = datetime.datetime.strftime(
        datetime.datetime.now() - datetime.timedelta(days=4), '%Y-%m-%d')
    end_date = datetime.datetime.strftime(
        datetime.datetime.now() - datetime.timedelta(days=3), '%Y-%m-%d')

    property_uri = 'http://www.bmimedia.net'

    #Create the request. Use the API tutorial to explain how the API works
    request = {
        'startDate': end_date,
        'endDate': end_date,
        'dimensions': ['page', 'query'],
        'rowLimit': 10
    }

    response = execute_request(service, property_uri, request)
    print_table(response, 'Top Queries', end_date)