Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 需要佩戴个人防护面具。请指定一个或多个有效路径_Android_Google Api_Kotlin_Google People - Fatal编程技术网

Android 需要佩戴个人防护面具。请指定一个或多个有效路径

Android 需要佩戴个人防护面具。请指定一个或多个有效路径,android,google-api,kotlin,google-people,Android,Google Api,Kotlin,Google People,Hi将此引用到call people/me API并获取此错误 01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request 01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err: { 01-12 12:

Hi将此引用到call people/me API并获取此错误

    01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err: {
01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err:   "code" : 400,
01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err:   "errors" : [ {
01-12 12:33:12.859 22112-22285/com.nuveda.gol W/System.err:     "domain" : "global",
01-12 12:33:12.860 22112-22285/com.nuveda.gol W/System.err:     "message" : "personFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/get.",
01-12 12:33:12.860 22112-22285/com.nuveda.gol W/System.err:     "reason" : "badRequest"
01-12 12:33:12.860 22112-22285/com.nuveda.gol W/System.err:   } ],
01-12 12:33:12.860 22112-22285/com.nuveda.gol W/System.err:   "message" : "personFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/get.",
01-12 12:33:12.860 22112-22285/com.nuveda.gol W/System.err:   "status" : "INVALID_ARGUMENT"
01-12 12:33:12.860 22112-22285/com.nuveda.gol W/System.err: }
我无法设置人员字段。任何人都可以通过参考该文档知道如何设置人员配置

这是我的密码:

 val SCOPE_USER_INFO = Scope("https://www.googleapis.com/auth/userinfo.profile")
        val SCOPE_USER_INFO = Scope("https://www.googleapis.com/auth/contacts.readonly")
        val SCOPE_EMAIL = Scope(Scopes.EMAIL)

        // Configure Google Sign In
        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(context.getString(R.string.default_web_client_id))
                .requestProfile()
                .requestScopes(SCOPE_USER_INFO, SCOPE_EMAIL)
                .requestEmail()
                .build()

        // [END config_signin]

        mGoogleApiClient = GoogleApiClient.Builder(context)
                .enableAutoManage(context as AppCompatActivity /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build()


private fun signIn() {
        val signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient)
        (context as AppCompatActivity).startActivityForResult(signInIntent, RC_SIGN_IN)
    }

private fun updateUI(user: FirebaseUser?) {
        if (user != null) {
            val account : GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
            if (account != null) {
                val googleProfileAsync  = GoogleProfileAsync(context = activity, account = account.account!!)
                googleProfileAsync.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
            }
        } else {
            signIn()
        }
    }

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == RC_SIGN_IN && data != null) {

            val task = GoogleSignIn.getSignedInAccountFromIntent(data)
            try {
                // Google Sign In was successful, authenticate with Firebase
                val account = task.getResult<ApiException>(ApiException::class.java)
                firebaseAuthWithGoogle(account)
            } catch (e: ApiException) {
                GOLLog.d("Google sign in failed" + e)
            }


        }
    }

private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
        GOLLog.d(TAG, "firebaseAuthWithGoogle:" + acct.id!!)
        showProgressDialog()
        val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(context as AppCompatActivity) { task ->
                    if (task.isSuccessful) {
                        // Sign in success, update UI with the signed-in user's information
                        val user = mAuth.currentUser
                        updateUI(user)
                    } else {
                        // If sign in fails, display a message to the user.
                        Toast.makeText(context, "Authentication failed.",
                                Toast.LENGTH_SHORT).show()
                        updateUI(null)
                    }

                    // ...
                }
    }

    private class GoogleProfileAsync internal constructor(context: LoginActivity, private val account: Account) : AsyncTask<Void, Void, List<Person>?>() {
            private val context: WeakReference<LoginActivity> = WeakReference(context)
            /** Global instance of the HTTP transport.  */
            private val HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport()
            /** Global instance of the JSON factory.  */
            private val JSON_FACTORY = JacksonFactory.getDefaultInstance()
            private val mProgressDialog: ProgressDialog =ProgressDialog(context)


            override fun onPreExecute() {
                super.onPreExecute()
                GOLLog.d("On PReExecute")
                    mProgressDialog.setMessage(context.get()?.getString(R.string.loading))
                    mProgressDialog.isIndeterminate = true
                    mProgressDialog.show()
            }

            override fun doInBackground(vararg voids: Void): List<Person>? {
                GOLLog.d("doInBackground")
                var response: List<Person>? = null
                try {


                    val scopes: MutableList<String> = mutableListOf("https://www.googleapis.com/auth/contacts.readonly"/*, "https://www.googleapis.com/auth/plus.login"*/)
                    val credential: GoogleAccountCredential = GoogleAccountCredential.usingOAuth2(
                            context.get(),
                            scopes
                    )
                    credential.selectedAccount = account

                    val service: People = People.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                   .setApplicationName("REST API sample")
                   .build()


                    val connectionsResponse: ListConnectionsResponse = service
                   .people()
                   .connections()
                   .list("people/me")
                   .execute()
                    response = connectionsResponse.connections

                } catch (e: UserRecoverableAuthIOException) {
                    e.printStackTrace()
                    GOLLog.d("Authentication Failed")
                } catch (e: IOException) {
                    e.printStackTrace()
                }

                return response
            }

            override fun onPostExecute(response: List<Person>?) {
                super.onPostExecute(response)
                GOLLog.d("onPostExecute")
                mProgressDialog.hide()
                if (response != null) {
                    GOLLog.d("Response "  + response)
                }

            }
        }
val SCOPE\u USER\u INFO=SCOPE(“https://www.googleapis.com/auth/userinfo.profile")
val SCOPE\u USER\u INFO=范围(“https://www.googleapis.com/auth/contacts.readonly")
val SCOPE_EMAIL=SCOPE(Scopes.EMAIL)
//配置谷歌登录
val gso=GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT\u SIGN\u-IN)
.requestIdToken(context.getString(R.string.default\u web\u client\u id))
.requestProfile()
.requestScopes(范围\用户\信息、范围\电子邮件)
.requestEmail()
.build()
//[结束配置\u登录]
mGoogleApiClient=GoogleApiClient.Builder(上下文)
.enableAutomanager(上下文为AppCompativeActivity/*FragmentActivity*/,this/*OnConnectionFailedListener*/)
.addApi(Auth.GOOGLE\u SIGN\u IN\u API,gso)
.build()
私人娱乐签到{
val signinint=Auth.GoogleSignInApi.getsigninint(mgoogleapclient)
(上下文作为应用程序活动)。startActivityForResult(签名、注册)
}
私人娱乐更新(用户:FirebaseUser?){
如果(用户!=null){
val帐户:GoogleSignInAccount?=GoogleSignIn.GetLastSignedAccount(上下文)
如果(帐户!=null){
val googleProfileAsync=googleProfileAsync(上下文=活动,帐户=帐户。帐户!!)
googleProfileAsync.executeOnExecutor(AsyncTask.THREAD\u POOL\u EXECUTOR)
}
}否则{
签名()
}
}
重写activityResult(请求代码:Int,结果代码:Int,数据:Intent?){
super.onActivityResult(请求代码、结果代码、数据)
if(requestCode==RC\u SIGN\u IN&&data!=null){
val task=GoogleSignIn.GetSignedAccountFromIntent(数据)
试一试{
//Google登录成功,通过Firebase验证
val account=task.getResult(ApiException::class.java)
firebaseAuthWithGoogle(帐户)
}捕获(e:异常){
GOLLog.d(“谷歌登录失败”+e)
}
}
}
私人娱乐firebaseAuthWithGoogle(账户:谷歌签名账号){
GOLLog.d(标签“firebaseAuthWithGoogle:+acct.id!!)
showProgressDialog()
val credential=GoogleAuthProvider.getCredential(acct.idToken,null)
mAuth.SIGNWITH凭证(凭证)
.addOnCompleteListener(作为AppCompatActivity的上下文){task->
如果(任务成功){
//登录成功,使用登录用户的信息更新UI
val user=mAuth.currentUser
updateUI(用户)
}否则{
//如果登录失败,则向用户显示消息。
Toast.makeText(上下文,“身份验证失败”,
吐司。长度(短)。show()
updateUI(空)
}
// ...
}
}
私有类GoogleProfileAsync内部构造函数(上下文:LoginActivity,私有val帐户:account):AsyncTask(){
私有val上下文:WeakReference=WeakReference(上下文)
/**HTTP传输的全局实例*/
private val HTTP_TRANSPORT=AndroidHttp.newCompatibleTransport()
/**JSON工厂的全局实例*/
private val JSON_FACTORY=JacksonFactory.getDefaultInstance()
private val mProgressDialog:ProgressDialog=ProgressDialog(上下文)
覆盖乐趣onPreExecute(){
super.onPreExecute()
GOLLog.d(“在执行前”)
mProgressDialog.setMessage(context.get()?.getString(R.string.loading))
mProgressDialog.isIndeterminate=true
mProgressDialog.show()
}
覆盖乐趣doInBackground(vararg voids:Void):列表{
GOLLog.d(“doInBackground”)
var响应:列表?=null
试一试{
val范围:MutableList=mutableListOf(“https://www.googleapis.com/auth/contacts.readonly"/*, "https://www.googleapis.com/auth/plus.login"*/)
val凭证:GoogleAccountCredential=GoogleAccountCredential.usingAuth2(
context.get(),
范围
)
credential.selectedAccount=帐户
val服务:People=People.Builder(HTTP_传输、JSON_工厂、凭证)
.setApplicationName(“REST API示例”)
.build()
val connectionsResponse:ListConnectionsResponse=服务
.people()
.connections()
.列表(“人/我”)
.execute()
response=connectionssponse.connections
}捕获(e:UserRecoverableAuthIOException){
e、 printStackTrace()
GOLLog.d(“身份验证失败”)
}捕获(e:IOException){
e、 printStackTrace()
}
返回响应
}
重写onPostExecute(响应:列表?){
super.onPostExecute(响应)
GOLLog.d(“onPostExecute”)
mProgressDialog.hide()
if(响应!=null){
GOLLog.d(“响应”+响应)
}
}
}
似乎您需要屏蔽

这也适用于

    ListConnectionsResponse connectionsResponse = service
                    .people()
                    .connections()
                    .list("people/me")
                    .set("personFields","names,addresses,birthdays,genders,phoneNumbers,photos")
                    .execute();
我试过了
    ListConnectionsResponse connectionsResponse = service
                    .people()
                    .connections()
                    .list("people/me")
                    .set("personFields","names,addresses,birthdays,genders,phoneNumbers,photos")
                    .execute();