# Get Fitbit Account Data

TIP

This guide assumes that your app has already been authorized and the snippet of code that I will show you can access to a valid FitbitCredentials instance, here called fitbitCredentials, the Fitbit OAuth 2.0 client ID, here called clientID, and the Fitbit client secret, here called clientSecret.

Account data (opens new window) contain details information about the user's account. In Fitbitter, a datapoint is expressed by the FitbitAccountData model. Fitbitter fetches a simplified version of Account data (opens new window) as described by Fitbit. In particular, an instance of FitbitAccountData has the following fields:

  /// The Fitbit user id.
  String? userID;

  /// The user's age.
  int? age;

  /// A flag the tells if the user is an ambassador.
  bool? ambassador;

  /// A flag the tells if the stride is automatically computed.
  bool? autoStrideEnabled;

  /// The user's average daily steps.
  int? averageDailySteps;

  /// An url pointing to the user avatar image.
  String? avatar;

  /// An url pointing to the user avatar image (150px).
  String? avatar150;

  /// An url pointing to the user avatar image (640px).
  String? avatar640;

  /// A flag the tells if the user is using the challeges (beta) feature.
  bool? challegesBeta;

  /// The clock display format used by the user.
  String? clockDisplayFormat;

  /// A flag the tells if the user is a corporate user.
  bool? corporate;

  /// A flag the tells if the user is a corporate user admin.
  bool? corporateAdmin;

  /// The user birth date.
  DateTime? dateOfBirth;

  /// The user's name.
  String? displayName;

  /// The user's name settings.
  String? displayNameSetting;

  /// The user's first name.
  String? firstName;

  /// The user's food locale.
  String? foodsLocale;

  /// The user's full name.
  String? fullName;

  /// The user's gender.
  String? gender;

  /// The glucose unit used by the user.
  String? glucoseUnit;

  /// The user's height.
  double? height;

  /// The unit used by the user for the height.
  String? heightUnit;

  /// A flag the tells if the bug report is enabled.
  bool? isBugReportEnabled;

  /// A flag the tells if the user is a child.
  bool? isChild;

  /// A flag the tells if the stride is a coach.
  bool? isCoach;

  /// The user's language locale.
  String? languageLocale;

  /// The user's last name.
  String? lastName;

  /// A flag the tells if the legal terms acceptance is required.
  bool? legalTermsAcceptRequired;

  /// The user's locale.
  String? locale;

  /// The date when the user subscribed to Fitbit.
  DateTime? memberSince;

  /// A flag the tells if the mfa is enabled.
  bool? mfaEnabled;

  /// The user's offset from UTC.
  int? offsetFromUTCMillis;

  /// A flag the tells if the user is an sdk developer.
  bool? sdkDeveloper;

  /// The user's sleep tracking.
  String? sleepTracking;

  /// The user's start day of week.
  String? startDayOfWeek;

  /// The user's stride length while running.
  double? strideLengthRunning;

  /// The user's stride length while running type.
  String? strideLengthRunningType;

  /// The user's stride length while walking.
  double? strideLengthWalking;

  /// The user's stride length while walking type.
  String? strideLengthWalkingType;

  /// The unit used by the user while swimming.
  String? swimUnit;

  /// The user's timezone.
  String? timezone;

  /// The unit used by the user while swimming.
  String? waterUnit;

  /// The unit used by the user to log water.
  String? waterUnitName;

  /// The user's weight.
  double? weight;

  /// The unit used by the user for the weight.
  String? weightUnit;

For example:

FitbitAccountData(userID: 7ML2XV, age: 30, ambassador: false, autoStrideEnabled: false, avatar: https://asset-service.fitbit.com/42ff6a70-9609-11ec-9efa-230d376b8cfc_profile_100_square.png, avatar150: https://asset-service.fitbit.com/42ff6a70-9609-11ec-9efa-230d376b8cfc_profile_150_square.png, avatar640: https://asset-service.fitbit.com/42ff6a70-9609-11ec-9efa-230d376b8cfc_profile_640_square.png, averageDailySteps: 9935, challegesBeta: null, clockDisplayFormat: null, corporate: false, corporateAdmin: null, dateOfBirth: 1992-03-13 00:00:00.000, displayName: Giacomo, displayNameSetting: name, firstName: Giacomo, foodsLocale: it_IT, fullName: Giacomo, gender: MALE, glucoseUnit: METRIC, height: 183.0, heightUnit: METRIC, isBugReportEnabled: false, isChild: false, isCoach: false, languageLocale: it_IT, lastName: , legalTermsAcceptRequired: true, locale: it_IT, memberSince: 2019-07-01 00:00:00.000, mfaEnabled: false, offsetFromUTCMillis: 7200000, sdkDeveloper: false, sleepTracking: Normal, startDayOfWeek: MONDAY, strideLengthRunning: 116.30000000000001, strideLengthRunningType: manual, strideLengthWalking: 75.9, strideLengthWalkingType: default, swimUnit: METRIC, timezone: Europe/Rome, waterUnit: METRIC, waterUnitName: ml, weight: 85.0, weightUnit: METRIC, )

Information about the user's Fitbit Account can be obtained in three steps:

# Step 1: Instanciate a manager

First, you need to instanciate a FitbitAccountDataManager

    FitbitAccountDataManager fitbitAccountDataManager = FitbitAccountDataManager(
        clientID: '<OAuth 2.0 Client ID>',
        clientSecret: '<Client Secret>'
    );

# Step 2: Create the request url

Then, you have to create a url object, FitbitAccountAPIURL as

    FitbitAccountAPIURL fitbitAccountApiUrl = FitbitAccountAPIURL.withCredentials(fitbitCredentials: fitbitCredentials);

# Step 3: Get the data

Finally you can obtain the Fitbit Account data using

    final fitbitAccountDatas = await fitbitAccountDataManager.fetch(fitbitAccountApiUrl);
    FitbitAccountData fitbitAccountData = fitbitAccountDatas[0] as FitbitAccountData;

WARNING

Fitbit Badges and Goal are not currently fetched. It will be matter of future work.