2014-11-20 57 views
2

我有一個用戶使用google oauth2登錄的Web應用程序。什麼是最簡單的方式來檢測用戶是否通過谷歌應用程序市場登錄?

我有一個谷歌應用程序市場上市這個應用程序,和谷歌oauth2用戶的一部分不需要授予我的應用程序的權限,因爲他們的谷歌應用程序域管理員在安裝應用程序市場上市時做到了。

我希望能夠檢測到第二組用戶,分析應用程序市場列表被用於登錄到我的應用程序的頻率。目前,所有的google oauth2登錄都與我的應用程序相同。

是否有一個簡單的API調用可以確定當前用戶是否在該組中?

+0

我認爲也許有一個來分析它通過收集用戶的登錄電子郵件地址,以查看用戶登錄的域的方式與...一起。您可以通過以下鏈接找到收集登錄電子郵件地址的方式:https://developers.google.com/+/api/oauth – gui47 2014-11-21 19:45:04

+0

是否可以查詢特定域名是否在應用市場中安裝了我們的商品信息? – 2014-11-25 18:34:32

+0

是的。客戶許可API允許您檢索由客戶域標識的客戶的許可狀態。您可以在以下鏈接找到更多信息:https://developers.google.com/google-apps/marketplace/v2/developers_guide – gui47 2014-11-25 19:10:43

回答

1

我用這個代碼找出市集信息對於給定的應用標識和目標域:

InputStream p12File = Config.class.getResourceAsStream(Config.SERVICE_ACCOUNT_PRIVATE_KEY_RESOURCE_PATH); 
PrivateKey serviceAccountPrivateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), p12File, "notasecret", "privatekey", "notasecret"); 

JsonFactory jsonFactory = new JacksonFactory(); 
HttpTransport t = GoogleNetHttpTransport.newTrustedTransport(); 

GoogleCredential.Builder bgc = new GoogleCredential.Builder() 
      .setTransport(t) 
      .setJsonFactory(jsonFactory) 
      .setServiceAccountScopes(Collections.singleton("https://www.googleapis.com/auth/appsmarketplace.license")) 
      .setServiceAccountPrivateKey(serviceAccountPrivateKey) 
      .setServiceAccountId(Config.SERVICE_ACCOUNT_ID); 

GoogleCredential gc = bgc.build(); 
String token = gc.getAccessToken(); 
if(token == null) { 
    gc.refreshToken(); 
    token = gc.getAccessToken(); 
} 

HttpGet request = new HttpGet("https://www.googleapis.com/appsmarket/v2/customerLicense/" + applicationId + "/" + customerDomain); 
request.setHeader("Authorization", "Bearer " + token); 

DefaultHttpClient client = new DefaultHttpClient(httpParams); 
HttpResponse resp = client.execute(request); 
// ... read API JSON response 
相關問題