Google Fit API OAUTH问题 [英] Google fit API OAUTH Issue
问题描述
我正在尝试构建一个计步器应用程序,作为测试,我从github下载了android fit代码并运行了basicsensorsAPI:
I'm trying to build a step counter application, as a test i downloaded the android fit code from github and ran the basicsensorsAPI:
为了获取步数而不是位置,我将数据类型更改为 TYPE_STEP_COUNT_CUMULATIVE和TYPE_DERIVED (原始代码为 TYPE_LOCATION_SAMPLE和TYPE_RAW ).但是,一旦我这样做,OAUTH就会停止工作,而且我不确定为什么会造成问题.
In order to get stepcount instead of location I changed the data type to TYPE_STEP_COUNT_CUMULATIVE and TYPE_DERIVED, (the orignials are TYPE_LOCATION_SAMPLE and TYPE_RAW). But as soon as I do this the OAUTH stops working, and i'm not sure why this is creating an issue.
这是更改后的代码:
private void findFitnessDataSources() {
// [START find_data_sources]
// Note: Fitness.SensorsApi.findDataSources() requires the ACCESS_FINE_LOCATION permission.
Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
// At least one datatype must be specified.
.setDataTypes(DataType.TYPE_STEP_COUNT_CUMULATIVE)
// Can specify whether data type is raw or derived.
.setDataSourceTypes(DataSource.TYPE_DERIVED)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
Log.i(TAG, "Result: " + dataSourcesResult.getStatus().toString());
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Log.i(TAG, "Data source found: " + dataSource.toString());
Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());
//Let's register a listener to receive Activity data!
if (dataSource.getDataType().equals(DataType.TYPE_STEP_COUNT_CUMULATIVE)
&& mListener == null) {
Log.i(TAG, "Data source for LOCATION_SAMPLE found! Registering.");
registerFitnessDataListener(dataSource,
DataType.TYPE_STEP_COUNT_CUMULATIVE);
}
}
}
});
// [END find_data_sources]
}
这是原始代码:
private void findFitnessDataSources() {
// [START find_data_sources]
// Note: Fitness.SensorsApi.findDataSources() requires the ACCESS_FINE_LOCATION permission.
Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
// At least one datatype must be specified.
.setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
// Can specify whether data type is raw or derived.
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
Log.i(TAG, "Result: " + dataSourcesResult.getStatus().toString());
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Log.i(TAG, "Data source found: " + dataSource.toString());
Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());
//Let's register a listener to receive Activity data!
if (dataSource.getDataType().equals(DataType.TYPE_LOCATION_SAMPLE)
&& mListener == null) {
Log.i(TAG, "Data source for LOCATION_SAMPLE found! Registering.");
registerFitnessDataListener(dataSource,
DataType.TYPE_LOCATION_SAMPLE);
}
}
}
});
// [END find_data_sources]
}
我得到以下输出:应用程序需要用户的oAuth同意.
I get this output: Application needs oAuth consent from the User.
推荐答案
我也遇到了这个问题.
如果您遇到此问题,则需要征求许可:只需将此代码添加到onResult()
方法
I had also faced this problem.
You need to ask for a permission if you face this problem: just add this code inside your onResult()
method
if (dataSourcesResult.getStatus().getStatusCode()==5000)
{
try {
dataSourcesResult.getStatus().startResolutionForResult(SplashActivity.this,10);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
并在onActivityResult
中,再次调用您的方法
and in onActivityResult
, call again your method
if (requestCode==10 && resultCode==RESULT_OK)
{
findFitnessDataSources();
}
您也可以在此处查看更多信息,此处. 请访问此网址.它可以为您解释有关Google健身的所有状态代码和错误
You can also check here for more info here. Please visit this url. It can explain you all the status code and error regarding google fit
这篇关于Google Fit API OAUTH问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!