5

मेरा ऐप उपयोगकर्ताओं को Google प्लस के साथ लॉगिन करने की अनुमति देता है, और उनका नाम और ईमेल पता प्राप्त करता है। मुझे टोकन तक पहुंचने का प्रयास किया गया है।एक्सेस टोकन पुनर्प्राप्त: शून्य। com.google.android.gms.auth.GoogleAuthException: अज्ञात

कोड टोकन का उपयोग करने की:

Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();   
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); 
     AccountManager am = AccountManager.get(this); 

     final Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); 

     AsyncTask<Void, Void, String> task2 = new AsyncTask<Void, Void, String>() { 
      public static final int REQUEST_CODE_TOKEN_AUTH = 100; 

      @Override 
      protected String doInBackground(Void... params) { 
       String mScope="audience:server:client_id:899555500747-38rpnq51of946grhdvofck7r8u5p09cd.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login"; 
// Get the token for the current user 
       String token = null; 
       try { 
        token = GoogleAuthUtil.getToken(getApplicationContext(), Plus.AccountApi.getAccountName(mGoogleApiClient), mScope); 
        Log.i("G token", token); 
       } catch (IOException transientEx) { 
        // Network or server error, try later 
        Log.e(TAG, transientEx.toString()); 
       } catch (UserRecoverableAuthException e) { 
        // Recover (with e.getIntent()) 
        Log.e(TAG, e.toString()); 
        Intent recover = e.getIntent(); 
        startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH); 
       } catch (GoogleAuthException authEx) { 
        // The call is not ever expected to succeed 
        // assuming you have already verified that 
        // Google Play services is installed. 
        Log.e(TAG, authEx.toString()); 
       } 
       return token; 
      } 
      @Override 
      protected void onPostExecute(String token) { 
       Log.i(TAG, "Access token retrieved:" + token); 
      } 

     }; 
     task2.execute(); 

त्रुटि:

01-27 23:42:14.877 30994-31262/com.unicloud.mittal E/loginWithGooglePlus﹕ com.google.android.gms.auth.GoogleAuthException: Unknown 
01-27 23:42:14.877 30994-30994/com.unicloud.mittal I/loginWithGooglePlus﹕ Access token retrieved:null 

मैं विभिन्न समाधान जो मैं stackoverflow पर मिल सकता है की कोशिश की है। फिलहाल, मैं dev console से "सेवा खाता" से क्लाइंट आईडी का उपयोग कर रहा हूं, मैंने इसे "एंड्रॉइड एप्लिकेशन के लिए क्लाइंट आईडी" के लिए उपयोग करने का भी प्रयास किया है, फिर भी यह वही त्रुटि दिखाता है।

कृपया मुझे बताएं कि मैं क्या गलत कर रहा हूं? धन्यवाद।

उत्तर

5

मैं इस

String mScope = "oauth2:https://www.googleapis.com/auth/plus.login"; 

मैं पहुँच टोकन मिल गया के साथ इस लाइन

String mScope="audience:server:client_id:899555500747-38rpnq51of946grhdvofck7r8u5p09cd.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login"; 

बदल कर भी इस सवाल का हल, और अगर मैं सही कर रहा हूँ मैं सोच रहा था। इसलिए मैंने सत्यापित किया कि टोकन सही था या नहीं। मैंने इस पते पर जाने की कोशिश की, मैंने accessToken को टोकन के साथ पुनर्प्राप्त किया।

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=accessToken 

यह मुझे इस प्रकार का आउटपुट दिखाता है।

{ 
    "issued_to": "xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", 
    "audience": "xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", 
    "user_id": "xxxxxxxxxxxxxxxxxxxxxxx", 
    "scope": "https://www.googleapis.com/auth/userinfo.profile https://gdata.youtube.com", 
    "expires_in": 3019, 
    "access_type": "online" 
    } 

issued_to में यह मेरे Android एप्लिकेशन इस टोकन का मतलब है कि मेरे मुवक्किल आईडी पर जारी किया जाता है के लिए अपने ग्राहक आईडी से पता चला है। तो मुझे लगता है कि मैं सही रास्ते पर हूं।

संबंधित मुद्दे