This Spring Boot application performs sentiment analysis on social media data (Twitter, Facebook, Instagram). It uses OpenAI via Spring AI to analyze the sentiment of each post or comment.
- β Analyze tweets (including retweets) by hashtag
- β Analyze Facebook post comments
- β Analyze Instagram media comments
- β Tag sentiment as Positive, Neutral, Negative, or Mixed
- β Store to H2 in-memory database
- β Assign town/location based on content text
- β Multi-tag (topics)
- β Per-product sentiment classification
- β REST API to trigger analysis or retrieve results
- Java 21+
- Maven
- Access tokens:
OPENAI_API_KEYTWITTER_BEARER_TOKENFACEBOOK_ACCESS_TOKEN&PAGE_IDINSTAGRAM_ACCESS_TOKEN&USER_ID
Set your credentials in src/main/resources/application.yml:
openai:
api-key: sk-xxx
twitter:
bearer-token: YOUR_TWITTER_BEARER_TOKEN
facebook:
page-id: YOUR_PAGE_ID
access-token: YOUR_ACCESS_TOKEN
instagram:
user-id: YOUR_USER_ID
access-token: YOUR_ACCESS_TOKEN./mvnw spring-boot:run# Analyze tweets by hashtag
curl http://localhost:8080/sentiments/twitter/AI
# Analyze Facebook comments
curl http://localhost:8080/sentiments/facebook
# Analyze Instagram comments
curl http://localhost:8080/sentiments/instagram
# Get all sentiments
curl http://localhost:8080/sentiments
# Filter by location
curl http://localhost:8080/sentiments/location/Jakarta"The delivery of Product X was excellent, but the support for Product Y was disappointing."{
"sentiment": "Mixed",
"objectTags": ["Product X", "Product Y"],
"scopes": ["Delivery", "Support"],
"products": [
{"product": "Product X", "sentiment": "Positive"},
{"product": "Product Y", "sentiment": "Negative"}
]
}Location is automatically inferred from text using simple keyword matching (e.g., "Jakarta", "Bandung").
- SocialPost
- location: "Jakarta"
- sentiment: "Mixed"
- objectTags: ["Product X", "Product Y"]
- scopes: ["Delivery", "Support"]
- SentimentLabels
- Product X β Positive
- Product Y β Negative