我们正在使用Flutter构建一个移动的应用程序,它可以读取睡眠数据并显示基于睡眠数据的 Jmeter 板,
我们正在使用Firebase进行社交登录。目前,我们支持谷歌,Facebook和自定义电子邮件/基于密码的登录。
谷歌登录
当用户使用Google帐户登录时,应用程序将获取睡眠数据。我们正在传递Google API范围,如下所示。
FirebaseAuth.instance, UserRepository(), GoogleSignIn(scopes:[
'https://www.googleapis.com/auth/fitness.sleep.read',
])),
Facebook登录
如果用户使用Facebook帐户登录,我们会收到以下错误。不知道如何在Facebook登录中传递Google API范围。我收到下面的问题:
W/FLUTTER_HEALTH::ERROR(31643): There was an error getting the sleeping data!
W/FLUTTER_HEALTH::ERROR(31643): 4: The user must be signed in to make this API call.
W/FLUTTER_HEALTH::ERROR(31643): [Ljava.lang.StackTraceElement;@7eb1aa0
W/FLUTTER_HEALTH::ERROR(31643): There was an error getting the sleeping data!
W/FLUTTER_HEALTH::ERROR(31643): 4: The user must be signed in to make this API call.
W/FLUTTER_HEALTH::ERROR(31643): [Ljava.lang.StackTraceElement;@ef740cc
W/FLUTTER_HEALTH::ERROR(31643): There was an error getting the sleeping data!
W/FLUTTER_HEALTH::ERROR(31643): 4: The user must be signed in to make this API call.
W/FLUTTER_HEALTH::ERROR(31643): [Ljava.lang.StackTraceElement;@abd9db8
请看一下我们使用的代码:
`Future fetchSleepData() async {
List<HealthDataPoint> _healthDataList = [];
final types = [
HealthDataType.SLEEP_ASLEEP,
HealthDataType.SLEEP_AWAKE,
HealthDataType.SLEEP_IN_BED
];
final permissions = [
HealthDataAccess.READ,
HealthDataAccess.READ,
HealthDataAccess.READ
];
final now = DateTime.now();
final yesterday = now.subtract(Duration(days: 10));
HealthFactory health = HealthFactory();
bool requested =
await health.requestAuthorization(types, permissions: permissions);
await Permission.activityRecognition.request();
await Permission.location.request();
if (requested) {
try {
// fetch health data
List<HealthDataPoint> healthData =
await health.getHealthDataFromTypes(yesterday, now, types);
// save all the new data points (only the first 100)
_healthDataList.addAll((healthData.length < 100)
? healthData
: healthData.sublist(0, 100));
} catch (error) {
print("Exception in getHealthDataFromTypes: $error");
}
// filter out duplicates
_healthDataList = HealthFactory.removeDuplicates(_healthDataList);
// print the results
_healthDataList.forEach((x) => print(x));
}
}`
请帮助我使用Flutter Firebase从Google API读取睡眠数据。用户使用Facebook Auth登录。
任何建议将不胜感激。
1条答案
按热度按时间ve7v8dk21#
Google服务无法通过Facebook授权访问。为此,需要使用Google auth。使用Google Auth作为您的主要登录方法,并仅在必要时使用Facebook Auth。