
typescriptconst fetchGarminActivities = async (event: any) => {const oauthToken = event.oauthToken;const oauthTokenSecret = event.oauthTokenSecret;const currentDate = new Date();const summaryStartTimeInSeconds = Math.floor(Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate(), 0, 0, 0, 0) / 1000);const summaryEndTimeInSeconds = summaryStartTimeInSeconds + 86400;try {const response = await axios({method: "GET",url: "https://apis.garmin.com/wellness-api/rest/backfill/activityDetails",headers: generateOauthSignatureHeaders({method: "GET",url: "https://apis.garmin.com/wellness-api/rest/backfill/activityDetails",oauthToken,oauthTokenSecret,summaryStartTimeInSeconds,summaryEndTimeInSeconds,}),params: {summaryStartTimeInSeconds,summaryEndTimeInSeconds,},});// Process and store the activity data} catch (error) {console.error(error?.response?.data ?? error);}};

typescriptconst fetchPolarActivityList = async (event: any) => {const accessToken = event.accessToken;const userId = event.userId;try {const response = await axios({method: "GET",url: `https://www.polaraccesslink.com/v3/users/${userId}/activity-transactions`,headers: {Authorization: `Bearer ${accessToken}`,},});// Process and store the activity data} catch (error) {console.error(error?.response?.data ?? error);}};
typescriptconst fetchFitbitActivities = async (event: any) => {const accessToken = event.accessToken;const userId = event.userId;try {const response = await axios({method: "GET",url: `https://api.fitbit.com/1/user/${userId}/activities/list.json`,headers: {Authorization: `Bearer ${accessToken}`,},params: {sort: 'desc',offset: 0,limit: 100,},});// Process and store the activity data} catch (error) {console.error(error?.response?.data ?? error);}};
typescriptinitHealthKit = () => {let options = {permissions: {read: ['Height', 'Weight', PERMS.StepCount, PERMS.BodyFatPercentage,PERMS.Step, PERMS.DistanceWalkingRunning, PERMS.HeartRate,PERMS.BodyTemperature, PERMS.BloodPressureDiastolic,],write: ['Height', 'Weight'],},}AppleHealthKit.isAvailable((error, available) => {if (available) {AppleHealthKit.initHealthKit(options, (err, results) => {if (err) {console.error('Error initializing HealthKit', err);} else {console.log('HealthKit initialized successfully');}});} else {console.error('HealthKit is not available on this device');}});}
To create a unified experience, implement a robust backend system:
Example of storing activity data in DynamoDB:
typescriptconst createActivityEvent = async (eventInfo: {userId: string;title: string;latitude?: number;longitude?: number;fitbitLogId?: string;garminSummaryId?: string;polarExerciseId?: string;appleActivityId?: string;startDate?: string | null;endDate?: string | null;activityType: string;},healthMetrics: {avgHr: number | null;avgPace: number | null;calories: number | null;distanceInMeters: number | null;steps: number | null;vo2Max: number | null;},user: User) => {const date = new Date();const eventPayload = {TableName: process.env.EVENTS_TABLE_NAME as string,Item: {id: uuidv4(),userId: eventInfo.userId,title: eventInfo.title,startDate: eventInfo.startDate,endDate: eventInfo.endDate,activityType: eventInfo.activityType,healthMetrics: healthMetrics,createdAt: date.toISOString(),updatedAt: date.toISOString(),},};await dbClient.put(eventPayload).promise();};
By meticulously integrating various health tracking platforms into a single system, you can provide users with a comprehensive and seamless health monitoring experience. This unified approach not only simplifies data management for users but also enables more accurate insights and personalized recommendations. As you develop your integrated health tracking app, prioritize data accuracy, user privacy, and a smooth user experience across all connected devices and platforms.

Trong văn hóa châu Á, đặc biệt là ở Việt Nam, chúng ta thường nghe câu "Có công mài sắt, có ngày nên kim". Điều này hoàn toàn đúng với việc học lập trình. Việc code mỗi ngày, dù chỉ một chút, cũng như giọt nước mưa kiên trì rơi xuống, từng giọt một sẽ tạo nên đại dương mênh mông của kiến thức và kinh nghiệm.
Beiryu
Contributor

Public speaking is a skill that can open doors to countless opportunities, both in personal and professional life. However, for many people, the thought of standing in front of an audience and delivering a presentation can be daunting. The fear of public speaking, also known as glossophobia, is one of the most common phobias. But with the right mindset and techniques, anyone can overcome this fear and become a confident presenter.
Beiryu
Contributor