Set Up Google Cloud Platform Credentials
- Create a Google Cloud account if you don't already have one. Visit the Google Cloud Platform and sign up.
- After signing in, go to the Google Cloud Console.
- Create a new project by clicking on the project dropdown and selecting "New Project."
- Enable the necessary APIs, such as the Cloud Natural Language API, via the "API & Services" dashboard.
- Navigate to "IAM & admin" > "Service Accounts," then click "Create Service Account."
- Assign the necessary roles, such as "Editor" or "Viewer," to your service account.
- Generate a JSON key file for your service account and download it to your local machine.
Set Up SurveyMonkey Developer Application
- Sign into your SurveyMonkey account.
- Go to the SurveyMonkey Developer Portal.
- Create a new app and note down the client ID and client secret for authentication.
- Under "Scopes," select the permissions you require, such as "View surveys" and "View survey responses."
Install Required Libraries
- Ensure you have Python installed on your machine. Install the Google Cloud and SurveyMonkey libraries using pip.
pip install google-cloud-language surveymonkeyapi
Authenticate Google Cloud API
- Set the environment variable for Google application credentials using the path to your service account JSON file.
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-file.json"
Authenticate SurveyMonkey API
- Use OAuth2 for authentication. Implement a mechanism to obtain an access token using your client ID and client secret.
- SurveyMonkey provides a sample script here.
Access SurveyMonkey Survey Data
- Use the SurveyMonkey API to fetch survey data. Below is a Python snippet to get responses from a survey.
from surveymonkey import SurveyMonkeyAPI
api_key = "your_access_token"
sm = SurveyMonkeyAPI(api_key)
survey_id = "your_survey_id"
responses = sm.get_responses(survey_id=survey_id)
print(responses)
Analyze Survey Data with Google Cloud AI
- Utilize Google Cloud's Natural Language API to analyze text data from survey responses. Below is an example using the Python client library.
from google.cloud import language_v1
client = language_v1.LanguageServiceClient()
for response in responses:
text_content = response['data']
document = language_v1.Document(
content=text_content, type=language_v1.Document.Type.PLAIN_TEXT
)
sentiment = client.analyze_sentiment(document=document).document_sentiment
print(f'Text: {text_content}')
print(f'Sentiment: {sentiment.score}, {sentiment.magnitude}')
Visualize and Interpret the Data
- After processing, you can visualize the sentiment analysis results using tools like Matplotlib or Pandas DataFrames to gain insights into customer opinions.
import pandas as pd
import matplotlib.pyplot as plt
data = {'response_text': [], 'score': [], 'magnitude': []}
for response in responses:
text_content = response['data']
sentiment = client.analyze_sentiment(document=document).document_sentiment
data['response_text'].append(text_content)
data['score'].append(sentiment.score)
data['magnitude'].append(sentiment.magnitude)
df = pd.DataFrame(data)
df.plot(kind='bar', x='response_text', y='score')
plt.show()