2014-01-06 38 views
1

我下載了最新版本的GooglePlayServices,幷包含在我的應用程序中。我生成了我的調試密鑰的SHA1指紋,並將它們設置爲Google API Console。我只有一個應用程序。爲什麼Google+集成不適用於我的Android應用程序?

我使用谷歌加這樣的:

googlePlusClient = new PlusClient.Builder(getActivity(), new GooglePlayServicesClient.ConnectionCallbacks() { 
     @Override 
     public void onConnected(Bundle bundle) { 
      googlePlusClient.loadPeople(new PlusClient.OnPeopleLoadedListener() { 

       @Override 
       public void onPeopleLoaded(ConnectionResult connectionResult, PersonBuffer persons, String s) { 
        if(connectionResult.isSuccess()) { 
         ArrayList<String> result = new ArrayList<String>(); 
         for(Person person : persons) { 
          result.add(person.getId()); 
         } 
         // Some actions with the data 
        } 
       } 
      }, "me"); 

     } 

     @Override 
     public void onDisconnected() { 

     } 
    }, new GooglePlayServicesClient.OnConnectionFailedListener() { 
     @Override 
     public void onConnectionFailed(ConnectionResult connectionResult) { 
      if(connectionResult.hasResolution()) { 
       try { 
        connectionResult.startResolutionForResult(getActivity(), REQUEST_GOOGLE_AUTH); 
       } catch (IntentSender.SendIntentException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 
    }).setScopes(Scopes.PLUS_PROFILE).build(); 
    googlePlusClient.connect(); 

這:

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if(googlePlusClient != null && requestCode == REQUEST_GOOGLE_AUTH && resultCode == Activity.RESULT_OK) { 
     googlePlusClient.connect(); 
    } 
} 

我仍然得到403錯誤。這裏的LogCat這個:

E/Volley﹕ [907] ot.a: Unexpected response code 403 for https://www.googleapis.com/plus/v1/people/me 
D/GooglePlusPlatform﹕ Unexpected response code (403) when requesting: getPerson 
I/GooglePlusPlatform﹕ {"code":403,"errors":[{"message":"Access Not Configured","domain":"usageLimits","reason":"accessNotConfigured"}]} 

我做錯了什麼?

回答

0

好的,我找到了解決辦法。我不知道爲什麼,但我的調試密鑰中的指紋是錯誤的。我用這個代碼來獲取它們。希望這會對其他人有所幫助。

PackageInfo packageInfo = null; 
    try { 
     packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_SIGNATURES); 
    } catch (PackageManager.NameNotFoundException e) { 
     e.printStackTrace(); 
    } 
    Signature[] signatures = packageInfo.signatures; 
    byte[] cert = signatures[0].toByteArray(); 
    InputStream input = new ByteArrayInputStream(cert); 

    CertificateFactory cf = null; 
    try { 
     cf = CertificateFactory.getInstance("X509"); 
    } catch (CertificateException e) { 
     e.printStackTrace(); 
    } 
    X509Certificate c = null; 
    try { 
     c = (X509Certificate) cf.generateCertificate(input); 
    } catch (CertificateException e) { 
     e.printStackTrace(); 
    } 
    try { 
     MessageDigest md = MessageDigest.getInstance("SHA1"); 
     byte[] publicKey = md.digest(c.getPublicKey().getEncoded()); 

     StringBuffer hexString = new StringBuffer(); 
     for (int i=0;i<publicKey.length;i++) { 
      String appendString = Integer.toHexString(0xFF & publicKey[i]); 
      if(appendString.length()==1)hexString.append("0"); 
      hexString.append(appendString); 
     } 
     Log.d("SHA1", "Cer: " + hexString.toString()); 

    } catch (NoSuchAlgorithmException e1) { 
     e1.printStackTrace(); 
    } 
相關問題