google-python-api

How to get delegated credentials objects for invoking google apis?

不想你离开。 提交于 2021-02-19 05:21:40
问题 I am trying to fetch gsuite alerts via API. I have created a service account as per their docs and I have assigned that service account to my google cloud function. I do not want to use environment variables or upload credentials along with source code but I want leverage default service account used by function. from googleapiclient.discovery import build def get_credentials(): # if one knows credentials file location(when one uploads the json credentials file or specify them in environment

create new folder in google drive with rest api

喜你入骨 提交于 2021-01-28 02:52:36
问题 How can I create a new folder in google drive using python only if it doesn't exists? I am completely new to this google APIs and python. (I have an access token for my account and I want to create folder using that.) create folder import json import requests headers = {"Authorization": "Bearer Token"} data = { "name": "name", "mimeType": "application/vnd.google-apps.folder" } r = requests.post("https://www.googleapis.com/drive/v3/files", headers=headers,data = data) print(r.text) Only file

GCP BigQuery how to set expiration date to table by python api

╄→尐↘猪︶ㄣ 提交于 2020-03-25 18:52:46
问题 I am using BigQuery Python API to create table, and would like to set an expiration date to the table, so the table would be automatically dropped after certain days. Here is my code: client = bq.Client() job_config = bq.QueryJobConfig() dataset_id = dataset table_ref = client.dataset(dataset_id).table(filename) job_config.destination = table_ref job_config.write_disposition = 'WRITE_TRUNCATE' dt = datetime.now() + timedelta(seconds=259200) unixtime = (dt - datetime(1970,1,1)).total_seconds()

How to Skip Columns of CSV file

╄→尐↘猪︶ㄣ 提交于 2019-12-24 11:14:03
问题 I am trying to upload data from certain fields in a CSV file to an already existing table. From my understanding, the way to do this is to create a new table and then append the relevant columns of the newly created table to the corresponding columns of the main table. How exactly do I append certain columns of data from one table to another? As in, what specific commands? I am using the bigquery api and the python-client-library. 回答1: You can use pandas library for that. import pandas as pd

How to merge cells with Google Sheets API?

情到浓时终转凉″ 提交于 2019-12-23 09:49:04
问题 I am using the Python client for the Google Sheets API to build a spreadsheet. I am able to create a new sheet and update values in it, but I have been unable to merge cells for the header row that I want. top_header_format = [ {'mergeCells': { 'mergeType': 'MERGE_COLUMNS', 'range': { 'endColumnIndex': 3, 'endRowIndex': 1, 'sheetId': '112501875', 'startColumnIndex': 0, 'startRowIndex': 0 } }}, {'mergeCells': { 'mergeType': 'MERGE_COLUMNS', 'range': { 'endColumnIndex': 5, 'endRowIndex': 1,

Publish Google Sheet document to the web using Google Sheets API

夙愿已清 提交于 2019-12-13 00:36:38
问题 My goal is to publish a Google Sheet document to the web and get the link using Google Sheets API. I managed to publish it using this advice and now it says "published" in File -> Publish to the web tab. However, the link given on this tab is different from the original file id , and I don'k know how to get it with API. 回答1: Unfortunately, the URL of https://docs.google.com/spreadsheets/d/e/### Not fileId ###/pubhtml retrieved when the spreadsheet is published cannot be directly retrieved. At

Unable to export a google slide as pdf format on server side

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 04:54:10
问题 Here is my code for testing exporting files from google drive on server side. import logging from flask import Flask, render_template, request from googleapiclient.discovery import build from googleapiclient.http import MediaIoBaseDownload from oauth2client.client import AccessTokenCredentials import httplib2 import io app = Flask(__name__) @app.route('/gdrive/selectcallback') def userselectioncallback(): print "In user selection callback... " code = request.args.get('user_token') fileId =

How to export specific sheet using new (v3) google drive API

家住魔仙堡 提交于 2019-12-11 06:05:26
问题 I am trying to download specific sheet from a spread-sheet (on Google Drive) but unable to find a method to do so. I am using Python Client API library (v3) and passing file_id and mimeType in export_media() function as shown below: request = service.files().export_media(fileId=file_id,mimeType='text/csv') media_request = http.MediaIoBaseDownload(local_fd, request) This code always export the sheet which is present at first place. Can you please describe a method through which I can download

Is it possible to query Google Cloud Storage similar to using `ls` command in terminal?

让人想犯罪 __ 提交于 2019-12-11 05:47:34
问题 I am using the python library for querying Google Cloud Storage, and I am organizing information in Storage using a naming hierarchy. For example: my_bucket/simulations/version_1/data... my_bucket/simulations/version_2/data... my_bucket/simulations/version_3/data... my_bucket/other_data/more_data... My question is: is it possible to query using list_blobs or some other method to retrieve a list that contains just the versions from the "simulations" directory, and not all of the blobs below

Incomplete Google Drive REST API results for Team Drive files

家住魔仙堡 提交于 2019-12-11 05:07:55
问题 Problem During the first phase of my Team Drive backup system, I first need to scan files in the given Team Drive in order to determine which files to copy for backup. I (think?) have full permissions over the files & folders of the Team Drive, due to the credentials I use (set to Owner in the cloud console). Nevertheless, my problem is that when I query the REST API for a file listing of a given Team Drive, the results do not comply with the documentation. The returned file objects only