Google合作伙伴API所需的权限?

时间:2016-07-06 02:44:10

标签: python google-api

我正在尝试使用python从Google Partners API获取公司列表。我应该可以使用these methods,特别是companies().list(),但我一直收到错误

  

HttpError 403"来电者没有权限"

我正在尝试使用的代码:

import pprint
import httplib2
import sys

from apiclient.discovery import build
from oauth2client import tools
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow

scope = 'https://www.googleapis.com/auth/partners'
client_secret = 'mysecret' 
api_key       = 'mykey'
client_id     = 'mycid'

flow = OAuth2WebServerFlow(client_id, client_secret, scope)

def main():

storage = Storage('credentials7.dat')
credentials = storage.get()

if credentials is None or credentials.invalid:
    credentials = tools.run_flow(flow, storage, tools.argparser.parse_args())

http = httplib2.Http()
http = credentials.authorize(http)

service = build('partners', 'v2', developerKey=api_key, http=http)

try:

    # The Calendar API's events().list method returns paginated results, so we
    # have to execute the request in a paging loop. First, build the
    # request object. The arguments provided are:
    #   primary calendar for user
    request = service.companies().list()
    # Loop until all pages have been processed.
    while request != None:
        # Get the next page.
        response = request.execute()
        # Accessing the response like a dict object with an 'items' key
        # returns a list of item objects (events).
        for event in response.get('items', []):
        # The event object is a dict object with a 'summary' key.
            print event
        # Get the next request object by passing the previous request object to
        # the list_next method.
        request = service.events().list_next(request, response)

except AccessTokenRefreshError:
    # The AccessTokenRefreshError exception is raised if the credentials
    # have been revoked by the user or they have expired.
    print ('The credentials have been revoked or expired, please re-run'
           'the application to re-authorize')




if __name__ == '__main__':
  main()

以上代码是从日历示例修改的,因此可能存在其他问题。然而,权限错误出现在第41行:response = request.execute(),这就是我现在所担心的问题。

在我的Google开发者控制台上,我启用了合作伙伴API,并将其他类型的Auth 2.0凭据设置为。

我很难过为什么我没有权限访问我认为是公共数据的内容。

由于

0 个答案:

没有答案