1

我在尝试运行示例代码 (python) 以代表用户插入活动时收到 HTTP 500 错误。我已经设置了域范围的委派并包含了所有正确的范围。我已经成功运行域委派来创建圈子、将人员添加到圈子、阅读帖子、评论和个人资料,但由于某种原因,我无法让代码用于代表用户插入帖子。有任何想法吗?代码和错误如下(私人信息已编辑):

import httplib2
import pprint

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

SERVICE_ACCOUNT_EMAIL = 'svc-acct@developer.gserviceaccount.com'
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '/path/privatekey.pem'

USER_EMAIL = 'email@domain.com'
SCOPES = ['https://www.googleapis.com/auth/plus.me',
          'https://www.googleapis.com/auth/plus.stream.read',
          'https://www.googleapis.com/auth/plus.stream.write',
          'https://www.googleapis.com/auth/plus.circles.read',
          'https://www.googleapis.com/auth/plus.circles.write',
          'https://www.googleapis.com/auth/plus.profiles.read']

def authenticate():
  print 'Authenticate the domain for %s' % USER_EMAIL

  f = open(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
  key = f.read()
  f.close()

  credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
  scope=SCOPES, sub=USER_EMAIL)
  http = httplib2.Http()
  http = credentials.authorize(http)

  return build('plusDomains', 'v1', http=http)


def activitiesInsert(service):
  user_id = 'me'
  print 'Inserting activity'
  result = service.activities().insert(
      userId = user_id,
      body = {
         'object' : {
              'originalContent' : 'Happy Monday! #caseofthemondays'
          },
          'access' : {
              'items' : [{
                  'type' : 'domain'
              }],
              # Required, this does the domain restriction
              'domainRestricted': True
          }
      }).execute()
  print 'result = %s' % pprint.pformat(result)


if __name__ == '__main__':
  service = authenticate()
  activitiesInsert(service)

python addpost.py

验证 email@domain.com 的域

插入活动

回溯(最近一次通话最后):

文件“addpost.py”,第 72 行,在活动插入(服务)中

文件“addpost.py”,第 64 行,活动插入“domainRestricted”:True

文件“build/bdist.macosx-10.6-intel/egg/oauth2client/util.py”,第 132 行,位于 positional_wrapper

文件“build/bdist.macosx-10.6-intel/egg/apiclient/http.py”,

第 723 行,执行中

apiclient.errors.httperror

请求https://www.googleapis.com/plusDomains/v1/people/me/activities?alt=json时的 HttpError 500返回“”

4

0 回答 0