python - 将时间线卡推送到给定的用户 ID

标签 python google-mirror-api

我正在使用 Google Mirror API,并且正在努力寻找一种仅将卡片推送给特定用户的方法。

当我尝试使用以下 Python 代码发布卡片时,给出用户 ID ( 12345677 ):

 timeline_item = {'text': 'Test10'}
 timeline_item['recipients'] = [{'id':'12345677'}]
 self.mirror_service.timeline().insert(body=timeline_item).execute()

该卡片在所有其他测试用户的时间轴中可见。

我做错了什么?

最佳答案

看起来您正在使用 Python 进行编码并使用 Google APIs Client Library for Python 。要将时间线项目推送到特定用户 ID,请在创建镜像服务时设置用户 ID。 Mirror API Python Quickstart在其 notifications code 中有一个如何执行此操作的示例。 recipients 字段与项目被推送到谁的时间线无关。

from oauth2client.appengine import StorageByKeyName
from model import Credentials

self.mirror_service = create_service(
        'mirror', 'v1',
        StorageByKeyName(Credentials, MY_USER_ID, 'credentials').get())
timeline_item = {'text': 'Test10'}
self.mirror_service.timeline().insert(body=timeline_item).execute()

代码create_service

import httplib2
from apiclient.discovery import build

from model import Credentials

def create_service(service, version, creds=None):
  """Create a Google API service.

  Load an API service from a discovery document and authorize it with the
  provided credentials.

  Args:
    service: Service name (e.g 'mirror', 'oauth2').
    version: Service version (e.g 'v1').
    creds: Credentials used to authorize service.
  Returns:
    Authorized Google API service.
  """
  # Instantiate an Http instance
  http = httplib2.Http()

  if creds:
    # Authorize the Http instance with the passed credentials
    creds.authorize(http)

  return build(service, version, http=http)

关于python - 将时间线卡推送到给定的用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17835455/

相关文章:

python - 欧拉计划 #17 略微偏离

Python __getattribute__ 和 __setattr__

python - 如果命令行程序不确定 stdout 的编码,它应该输出什么编码?

google-mirror-api - 推送包含多张卡片的 bundle 时,如何更改通知级别?

python - 如何为 Glass 设置目标位置?

python - 将一系列整数映射到单个整数

python - Python 中四舍五入到最近的一天

java - 使用 GDK 检索 Google Glass 中的帐户

php - Google Glass 开发错误 : (403) Access Not Configured. 请使用 Google Developers Console 为您的项目激活 API

google-mirror-api - Playground 样本的许可证是什么?