没有令牌返回驱动器推送通知

时间:2014-08-05 18:32:52

标签: python google-drive-api

我正在为这样的网络应用的用户创建通知渠道:

channel_id = str(uuid.uuid4())
channel_type = 'web_hook'
channel_address = 'https://example.com/drive'
current_time_ms = int(round(time.time() * 1000))
    body = {
        'id': channel_id,
        'type': channel_type,
        'address': channel_address, 
        'token': username, 
        'expiration': (current_time_ms + 604800000) # expire 1 week from now
    }
response = user_drive_service.changes().watch(body=body).execute()
expiration_time = response['expiration']
print "Drive push channel created for " + username

我在创建

时得到这样的回复
{
    u'resourceUri': u'https://www.googleapis.com/drive/v2/changes?alt=json&includeDeleted=true&includeSubscribed=true&maxResults=100&alt=json', 
    u'kind': u'api#channel', 
    u'resourceId': u'9876lkjhg4321asdf', 
    u'token': u'a_username', 
    u'expiration': u'1407921041000', 
    u'id': u'123456abcd789efgh'
}

然后我收到了像

这样的通知
{
    u'kind': u'drive#change', 
    u'id': u'123456', # Doesn't match ID in response from channel creation...
    u'selfLink': u'https://www.googleapis.com/drive/v2/changes/123456'
}

但文档herehere表示token字段应该返回给我,因此我可以从中提取username。任何人都可以指出问题出在哪里吗?

1 个答案:

答案 0 :(得分:1)

所以,结果证明是我的基本错误。如果有人想知道 - 我试图获得这样的令牌

result = json.loads(request.data)
user_id = result['token']

我在问题中发布的结果是request.data的输出。我应该一直在做

token = request.headers.get('X-Goog-Channel-Token')

令牌,到期时间,资源ID等都在标题中。糟糕!