2015-09-26 93 views
0

我試圖檢查用戶是否已經安裝在我的Marketplace應用Python的谷歌CustomerLicense「未授權訪問的應用程序ID」

from oauth2client.client import SignedJwtAssertionCredentials 
import json 
from httplib2 import Http 
from apiclient.discovery import build 

fname = 'my-creds.json' 
scope = [ 
    'https://www.googleapis.com/auth/appsmarketplace.license' 
] 
applicationId='12345678' 
customerId='mydomain.com' 

json_key = json.load(open(fname)) 

credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope) 

http_auth = credentials.authorize(Http()) 

appsmarket = build('appsmarket', 'v2', http=http_auth) 

response = appsmarket.customerLicense().get(applicationId=applicationId, customerId=customerId).execute() 
print response 

我在同一個項目中創建一個服務帳戶,作爲我在谷歌的應用程序安慰。

但我不斷收到

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/appsmarket/v2/customerLicense/471879773528/ashish%40noodletools.com?alt=json returned "Not authorized to access the application ID"> 

回答

-1

你在保衛科服務帳戶添加到您的域的授權API客戶端? 看委派域範圍內的機關服務帳戶這裏:​​

委派域範圍內的機關服務帳戶,在谷歌Apps域的管理員必須完成以下步驟:

  1. 轉到您的Google Apps網域的管理控制檯。
  2. 從控件列表中選擇安全性。如果您未看到安全列表,請從頁面底部的灰色欄中選擇更多控件,然後從控件列表中選擇安全性。如果您看不到這些控件,請確保您是以該域的管理員身份登錄的。
  3. 選擇顯示更多選項,然後從選項列表中選擇高級設置。
  4. 在驗證部分選擇管理API客戶端訪問。
  5. 在客戶端名稱字段中輸入服務帳戶的客戶端ID。
  6. 在一個或多個API範圍字段中,輸入您的應用程序應被授予訪問權限的範圍列表。
  7. 點擊授權。

您的應用程序現在有權在您的域中以用戶身份進行API調用(以「模擬」用戶)。當您準備進行授權的API調用時,可以指定用戶模擬。