我正在尝试从Google表格中获取URL列表,然后为每个URL发出API请求并以JSON格式返回数据。目前,我可以从Google表格中检索列表,也可以请求手动输入的单个URL。
到目前为止,一切正常。我或多或少要求我提供下一步工作的指导。我是Python的新手,所以不确定下一步该怎么做。
这是JSON中单个URL的API请求的输出示例: {“ date”:“ 2019-02-07T00:00:00 + 0000”,“点击”:7},{“ date”:“ 2019-02-06T00:00:00 + 0000”,“点击”:7 },{“ date”:“ 2019-02-05T00:00:00 + 0000”,“ clicks”:5}
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 6 18:47:58 2018
@author: Dylan
"""
import requests
import json
import gspread
from oauth2client.service_account import ServiceAccountCredentials
#scope is just telling google what API you want to use because they have so
many
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('Bitly Click
Data-a892fb027ee3.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("Bit.ly Links & General Links").get_worksheet(0)
values_list = wks.col_values(2)
wks = json.dumps(str(wks))
print(wks.get_all_records())
url = "https://api-ssl.bitly.com/v4/bitlinks/THIS NEEDS TO BE THE URL LIST
HERE/clicks"
payload = ""
headers = {'authorization': 'Bearer ACCESS TOKEN HERE'}
response = requests.request("GET", url, data=payload, headers=headers)
print(response.text)