看起来您正在使用 Python 进行编码并使用Google APIs Client Library for Python。要将时间线项目推送到特定用户 ID,请在创建镜像服务时设置用户 ID。Mirror API Python 快速入门在其通知代码中提供了如何执行此操作的示例。该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)