如何从python服务器端代码插入googleglass镜像凭证?

2024-03-29 10:10:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要Python服务器的帮助来完成镜像代码的插入。我们正在使用Python Google API库将一个特殊的auth令牌插入镜像API,但是我得到的结果是空白的镜像帐户().insert().execute(),其中我应该至少得到一个错误或我们正在传递给Google镜像API的API令牌凭据的确认。在

这是我们的Python服务器代码,其中包含一些机密信息的修订,机密信息的私钥和客户机的密匙都在secret.json文件中,我们安全地存储在服务器上。在

with open(os.path.join(os.path.dirname(__file__), 'mirror-credentials.json')) as f:
    credentials_json = json.load(f)
    credentials = SignedJwtAssertionCredentials(
        service_account_name=credentials_json['client_email'],
        private_key=credentials_json['private_key'],
        scope='https://www.googleapis.com/auth/glass.thirdpartyauth',
    )

http = credentials.authorize(httplib2.Http())
mirror = apiclient.discovery.build('mirror', 'v1', http=http)

glass_request = mirror.accounts().insert(
    userToken=$glassware_gallery_user_token,
    accountType='com.mycompany',
    accountName="testAccountName",
    body={
        'features': ["a", "b", "c"],
        'password': $myapp_glass_auth_token,
        'userData': [{"key": "realName", "value": "Rusty Shackleford"}],
        'authTokens': [
        {"type": "drchrono_glass_token", "authToken": $myapp_glass_auth_token}
        ],
    },
)
retValue = glass_request.execute()

注意:$glassware_gallery_user_token是我们打开玻璃器皿时从谷歌应用程序库中传入的令牌(我们已经设置了玻璃器皿应用程序)。在

执行上面的代码,我们得到retValue的空值,打印时它是一个空字典:{}。从文档来看,这应该是一个错误消息或确认。在


针对评论:

下面是我们发送的请求的打印输出(通过在httplib2源代码中插入print语句获得):

^{pr2}$

我得到一个空白字典作为回应:{}

我可以看出,这实际上是在与谷歌服务公司对话,原因有二:

  1. 如果我将user_令牌更改为无效,代码将抛出异常。在
  2. 我可以在googledeveloper控制台中看到我们的API调用计数,将这些尝试作为对API配额的调用进行计数。在

Google服务器的响应中的实际数据(在httplib2中打印出来)的状态代码为204:

'' / '{'fp': , 'status': 204, 'will_close': False, 'chunk_left': 'UNKNOWN', 'length': 0, 'strict': 0, 'reason': 'No Content', 'version': 11, 'debuglevel': 0, 'msg': , 'chunked': 0, '_method': 'POST'}'

@TonyAllevato我正试着用accountManager.getAccounts();我只有一个类型的帐户”谷歌". getAccountsByType(“com.xxxxxx公司)返回一个空数组。在


Tags: key代码服务器comtokenauthapijson
1条回答
网友
1楼 · 发布于 2024-03-29 10:10:45

Insert Mirror API文档有点不正确。成功时,它返回一个空响应,状态头代码为204(http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)“无内容”。文档的某些部分使我相信它会在响应中回显凭证,但事实并非如此。在

另一方面,我能够调试为什么我不能让凭据加载到我的玻璃上,首先确保我可以从https://google.com/myglass商店在我的玻璃设备上安装我的临时玻璃器皿,以确保有连接。在

相关问题 更多 >