Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Social Media Analytics API is added #357

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion New_APIs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
|[AWS S3 Multimedia Storage Client API](./aws-client-api/)|This is a client API that facilitates interaction with an AWS S3 bucket for storing and retrieving multimedia files. By utilizing the provided functions, you can easily upload and download multimedia files to and from the S3 bucket.|
|[Music API Web Application](./music-api/)|You can access any song and listen to it. Below are some useful links and information.|
[Result-marks Data api ](./Result-marks_API/)|this is for those who want to make college management project they can simple take this api and connect to project easily|
|[Payment API](./Payment_API/)|This demonstrates how to integrate PayPal API for online payments. It handles payment success and cancellation scenarios.|
|[Payment API](./Payment_API/)|This demonstrates how to integrate PayPal API for online payments. It handles payment success and cancellation scenarios.|
|[Social Media Analytics API](./Social_Media_Analytics_API/)|This demonstrates how to create a Social Media Analytics API to retrieve user engagement data like posts, likes, comments, and shares.|
108 changes: 108 additions & 0 deletions New_APIs/Social_Media_Analytics_API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Social Media Analytics API

This is a simple Social Media Analytics API built using Node.js and Express. The API provides basic analytics data for users such as total posts, likes, comments, and shares.

## Project Structure

```
social-media-analytics-api/
├── README.md
├── app.js
├── package.json
└── routes/
└── analytics.js
```

## Installation

1. Clone the repository:
```
git clone https://github.com/yourusername/social-media-analytics-api.git
```

2. Navigate to the project directory:
```
cd social-media-analytics-api
```

3. Install the dependencies:
```
npm install
```

## Running the API

To start the server, run:
```
npm start
```

The server will start on port 3000 by default. You can access the API at `http://localhost:3000/api/analytics/:userId`.

## Endpoints

### GET /api/analytics/:userId

Fetch analytics data for a user.

#### Parameters

- `userId` (string): The ID of the user.

#### Response

- `200 OK`: Returns the analytics data for the user.
- `404 Not Found`: User not found.

#### Example

```
GET /api/analytics/user1

Response:
{
"posts": 120,
"likes": 340,
"comments": 45,
"shares": 67
}
```

## Mock Data

Currently, the API uses mock data for demonstration purposes. You can find the mock data in `routes/analytics.js`.

## License

This project is licensed under the MIT License.
```

### Instructions to Run the Code

1. **Clone the Repository**
```sh
git clone https://github.com/yourusername/social-media-analytics-api.git
```

2. **Navigate to the Project Directory**
```sh
cd social-media-analytics-api
```

3. **Install Dependencies**
```sh
npm install
```

4. **Start the Server**
```sh
npm start
```

5. **Access the API**
Open your browser or use a tool like Postman to make a GET request to:
```
http://localhost:3000/api/analytics/user1
```

Feel free to expand this example by adding more features like user authentication, database integration, or more detailed analytics.
11 changes: 11 additions & 0 deletions New_APIs/Social_Media_Analytics_API/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express');
const app = express();
const analyticsRoutes = require('./routes/analytics');

app.use(express.json());
app.use('/api/analytics', analyticsRoutes);

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
14 changes: 14 additions & 0 deletions New_APIs/Social_Media_Analytics_API/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "social-media-analytics-api",
"version": "1.0.0",
"description": "A simple Social Media Analytics API built using Node.js and Express",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "^4.17.1"
},
"author": "Pallasivasai",
"license": "MIT"
}
32 changes: 32 additions & 0 deletions New_APIs/Social_Media_Analytics_API/routes/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const express = require('express');
const router = express.Router();

// Mock data
const analyticsData = {
user1: {
posts: 120,
likes: 340,
comments: 45,
shares: 67
},
user2: {
posts: 95,
likes: 280,
comments: 32,
shares: 54
}
};

// Endpoint to get analytics data for a user
router.get('/:userId', (req, res) => {
const userId = req.params.userId;
const data = analyticsData[userId];

if (data) {
res.json(data);
} else {
res.status(404).json({ message: 'User not found' });
}
});

module.exports = router;
Loading