1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Unable to share google form created through google forms api

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    I am in the process of creating a google form through the google form API.

    These are the steps I have taken:


    1. I created a project here: https://console.cloud.google.com/apis/credentials/consent?project={project name} with the google forms api activated


    2. I have created a google form with the questions i would like to ask.

    The issues begin here:


    1. I am unable to see this google form in my forms location on my google account. The only way i can access it is by running the below code and clicking on the resulting url. Why can't i see the resulting google form on my google account?

      form_metadata = form_service.forms().get(formId=FORM_ID).execute() print(form_metadata) print(form_metadata['formId']) print(form_metadata['responderUri'])


    2. I am able to fill out the google form I created but am not sure how to retrieve the answers to the form? When looking online its says i need to also connect to the google sheet associated with the form but i am unsure how to do that.

    Just to review, i have created a google form that i can only access through a url in python and i do not know how to access the answers to the form.

    This was my attempt at trying to retrieve the answers to the form but i dont think its particularly close:

    # Import necessary libraries
    from googleapiclient.discovery import build
    from google.oauth2 import service_account
    import pandas as pd

    # Define the scope and credentials
    SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"]
    SERVICE_ACCOUNT_FILE = 'C:/python/nfl_poll_py/credentials.json' # Replace with the path to your credentials file

    # Load the service account credentials
    credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES)

    # Create a service object for the Google Sheets API
    sheets_service = build('sheets', 'v4', credentials=credentials)

    # Define the ID of the spreadsheet linked to your Google Form
    SPREADSHEET_ID = 'your_spreadsheet_id' # Replace with your Google Sheet ID
    RANGE_NAME = 'Sheet1!A1:Z1000' # Adjust the range to fit your needs

    # Retrieve the response data from the Google Sheet
    try:
    sheet = sheets_service.spreadsheets()
    result = sheet.values().get(spreadsheetId=SPREADSHEET_ID, range=RANGE_NAME).execute()
    values = result.get('values', [])

    if not values:
    print('No data found.')
    else:
    # Convert the data to a DataFrame for easier manipulation
    df_responses = pd.DataFrame(values[1:], columns=values[0])
    print(df_responses)
    except Exception as e:
    print(f"An error occurred while fetching responses: {e}")


    I've tried to see if there is a way to find the form on my google drive/google account but its not there. The code to create the form has work but i can't share it or get any data from it.

    Continue reading...

Compartilhe esta Página