中国大陆支持Google Fit和OAuth 2.0吗?

时间:2019-05-14 08:59:33

标签: oauth-2.0 google-fit great-firewall-of-china

在页面“ https://developer.android.com/training/wearables/apps/creating-app-china”中,明确指出“在中国支持“ Google Fit的累积步数计数器,移动分钟数和中心点”,以及“建议使用OAuth 2.0”,但是在我测试示例时“ BasicSensorsApi”,OAuth 2.0身份验证请求代码为“ GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this),FitnessOptions)”,而Google Fit客户端请求代码为“ Fitness.getSensorsClient(this,GoogleSignIn.getLastSignedInAccount(this))。 ....',这两个示例代码都需要GoogleSignIn,如您所知,没有VPN(中国可以在中国大陆的Google帐户中进行登录)不支持GoogleSignIn,并且我已经尝试运行该程序了未能在关闭VPN的情况下获得权限,而在打开VPN的情况下成功了,只是为了确定这一点,需要专业帮助来确认我是否正确。谢谢!!!

    /** Checks if user's account has OAuth permission to Fitness API. */
    private boolean hasOAuthPermission() {
        FitnessOptions fitnessOptions = getFitnessSignInOptions();
        return GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions);
    }
   /** Finds available data sources and attempts to register on a specific {@link DataType}. */
    private void findFitnessDataSources() {
        // [START find_data_sources]
        // Note: Fitness.SensorsApi.findDataSources() requires the ACCESS_FINE_LOCATION permission.
        Fitness.getSensorsClient(this, GoogleSignIn.getLastSignedInAccount(this))
                .findDataSources(
                        new DataSourcesRequest.Builder()
                                .setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
                                .setDataSourceTypes(DataSource.TYPE_RAW)
                                .build())
                .addOnSuccessListener(
                        new OnSuccessListener<List<DataSource>>() {
                            @Override
                            public void onSuccess(List<DataSource> dataSources) {
                                for (DataSource dataSource : dataSources) {
                                    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);
                                    }
                                }
                            }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                Log.e(TAG, "failed", e);
                            }
                        });
        // [END find_data_sources]
    }

0 个答案:

没有答案