コード例 #1
0
    def export(
        self,
        statement_execution_id,
        uid,
        sheet_url=None,
        worksheet_title="Sheet1",
        start_cell="A1",
    ):
        sheet = None
        try:
            credentials = self.get_credentials(uid)
            gc = gspread.authorize(credentials)
            with gspread_sheet(
                gc, sheet_url, f"Querybook Result {statement_execution_id}"
            ) as sheet:
                self.write_csv_to_sheet(
                    sheet,
                    statement_execution_id,
                    worksheet_title,
                    start_cell,
                )

            return f"https://docs.google.com/spreadsheets/d/{sheet.id}"
        except RefreshError:
            # Invalidate user access token
            update_user_properties(current_user.id, gspread_token=None)
            # Continue to raise the error for the frontend client to see
            raise Exception("Invalid Google credentials, please try again.")
コード例 #2
0
def gspread_oauth_call_back():
    try:
        code = request.args.get("code")
        token = _google_flow.fetch_token(code=code)
        update_user_properties(current_user.id, gspread_token=token)

    except Exception as e:
        return """
            Failed to obtain credentials, reason: {}
        """.format(str(e))

    return """