Google Search Console API-批处理请求-Python

我正在使用Google Search Console API来获取每日数据,但是这太慢了,因为我也试图通过一些复杂的API请求来克服采样问题。

现在我正在查看批处理请求以执行相同的操作,但是文档非常少,没有任何示例。

我现在要做什么 我碰到了这个:https://developers.google.com/gmail/api/guides/batch 而且我可以看到批处理请求的格式,但是尽管我付出了所有努力,但我还是无法在Postman中提出正确的请求。

我也遇到了这个问题:Batch Request in python to Google Search Console API 而且仍然不确定在身份验证后我应该如何使用service对象来实际生成批处理请求。

代码(我很喜欢):

from googleapiclient.http import BatchHttpRequest

class ExtractBulk:
    def __init__(self):
        self.data = []

    def callback(self,request_id,response,exception):
        if exception is not None:
            print(exception)
            pass
        else:
            print(request_id)
            self.data.append(response)
    
    def batchReq(self,req1,req2):
        batch = BatchHttpRequest()
        batch.add(req1,self.callback,request_id='001')
        batch.add(req2,request_id='002')

        batch.execute()

        print(self.data)

def main():

    service = authorize_creds() // just a function to do oauth2 authentication.

    request_body_1 = {
        "startDate": "2015-01-01","endDate": "2016-01-01","dimensions": ["country","device"]
    }

    request_body_2 = {
        "startDate": "2016-01-01","endDate": "2017-01-01","device"]
    }

    s1 = service.searchanalytics().query(siteUrl=property_uri,body=request_body_1)
    s2 = service.searchanalytics().query(siteUrl=property_uri,body=request_body_2)
    batchReq(s1,s2)


This code is not really complete. For example: Where should I add `https://www.googleapis.com/batch/webmasters/v3` while using googleapi python library.

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...