1

エンドポイントからクライアント ライブラリを生成し、エンドポイントへの認証済み呼び出しに適切な資格情報 (クライアント ID は 100% 正しい) も渡しました。

しかし、コードを実行すると、まだこのエラーが発生します。

com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
            at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:286)
            at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
            at com.projects.malaysiakini.Home$ContentApi.doInBackground(Home.java:165)
            at com.projects.malaysiakini.Home$ContentApi.doInBackground(Home.java:141)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
     Caused by: com.google.android.gms.auth.GoogleAuthException: Unknown
            at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
            at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
            at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:255)
            at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:279)
            at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
            at com.projects.malaysiakini.Home$ContentApi.doInBackground(Home.java:165)
            at com.projects.malaysiakini.Home$ContentApi.doInBackground(Home.java:141)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)

これは以下の私のコードです:

 private class ContentApi extends AsyncTask<Void,Void,String>{

       @Override
       protected String doInBackground(Void... params) {
           String response = null;


           try {
               settings = getActivity().getSharedPreferences("MApi", Context.MODE_PRIVATE);
               credential = GoogleAccountCredential.usingAudience(getActivity(), CLIENT_ID);
               setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

               Core.Builder builder = new Core.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential);
               builder.setApplicationName(getActivity().getPackageName());

               service = builder.build();



               if (credential.getSelectedAccountName() != null) {
                   // Already signed in, begin app!

                response = service.info().execute().getLang();
               }//end if
               else {
                   chooseAccount();
               }

               }//end try
               catch(IOException ex){
                   Log.d("MkiniCore", ex.getMessage(), ex);
               }//end catch



           return response;
       }//end doInBackground

       @Override
       protected void onPostExecute(String s) {
          textView.setText(s);
       }
   }

コードを編集して以下の回答にしましたが、まだこのエラーが発生しています

これは、アカウント ピッカーのコードです。

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            case REQUEST_ACCOUNT_PICKER:
                if (data != null && data.getExtras() != null) {
                    String accountName =
                            data.getExtras().getString(
                                    AccountManager.KEY_ACCOUNT_NAME);
                    if (accountName != null) {
                        setSelectedAccountName(accountName);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString(PREF_ACCOUNT_NAME, accountName);
                        editor.commit();
                        // User is authorized.
                    }
                }
                break;
        }
    }

これは setSelectedAccountName メソッドです

private void setSelectedAccountName(String accountName){
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(PREF_ACCOUNT_NAME, accountName);
        editor.commit();
        credential.setSelectedAccountName(accountName);
        this.accountName = accountName;
    }//end setSelectedAccountName
4

1 に答える 1