
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.

Làm việc trong ngành phát triển phần mềm được một thời gian, tôi nhận ra một điều thú vị: không phải lúc nào code đẹp cũng đồng nghĩa với thành công về mặt kinh doanh. Hãy cùng tôi đi sâu vào một vài ví dụ điển hình và bài học từ thực tế.
Beiryu
Contributor

Hey there! This piece will show you how to supercharge your page loading on NextJs with data caching. It's pretty cool, you can use
Beiryu
Contributor