是否可以使用Google+域名API访问不属于域名的用户?

时间:2016-02-17 16:56:50

标签: python-2.7 api google-plus google-oauth

欢迎任何有任何建议帮助的人

问题:

是否可以使用“Google+域名API”访问非域Google+个人资料?

对于非域名关联的Google+帐户帐户,是否只能使用“Google+ API”?

有没有办法使用标准OAuth 2.0客户端凭据而不是服务帐户来完成以下操作?

背景:

我正在尝试使用Google+域名API for Python从Linux设备上传.jpg图像,并插入我的个人Google+个人资料/帐户。

此帐户不属于域名,我的应用程序不会访问任何其他Google+用户的数据。我创建了一个服务帐户和PKCS 12密钥,其中包含我用于授权的“所有者”权限。注意我没有创建域范围授权,因为我认为没有与我的个人Google+帐户相关联的域。

Getting Error 403 trying to access Google+ Domains using a Service Account

googleapiclient.errors.HttpError: <HttpError 403 when requesting 
https://www.googleapis.com/upload/plusDomains/v1/people/me/media/cloud?
uploadType=multipart&alt=json returned "Forbidden">

执行media()。insert()到集合'cloud'时会返回“Forbidden”错误。下面是我在开发人员指南中找到的示例汇编的python代码。

import httplib2
import pprint
import sys

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

SCOPES = ['https://www.googleapis.com/auth/plus.me',
          'https://www.googleapis.com/auth/plus.media.upload',
          'https://www.googleapis.com/auth/plus.stream.write']

def main(argv):

f = file('Trebor NAO Access-c35352d48d33.p12', 'rb')
key = f.read()
f.close()

credentials = SignedJwtAssertionCredentials('trebor-nao-access-service-659@trebor-nao-access.iam.gserviceaccount.com', key, SCOPES)
http = httplib2.Http()
http = credentials.authorize(http)

service = build(“plusDomains”, “v1”, http=http)

try:
  user_id = 'me'

  print('Uploading a picture of a box of MiniWheats cereal')
  result = service.media().insert(
      media_body = 'MiniWheats.jpg',
      body = {'displayName': 'MiniWheats.jpg'},
      userId = user_id,
      collection = 'cloud',
  ).execute()
  print('result = %s' % pprint.pformat(result))

  media_id = result.get('id')
  print('MediaID of MiniWheats.jpg: %s' % media_id)

if __name__ == '__main__':
  main(sys.argv)

非常感谢您给予的任何建议。

Robert Dixey

0 个答案:

没有答案
相关问题