Пример #1
0
def authenticate(credentials):
    client = credentials.authorize()
    service = discovery.build('analytics', 'v3', http=client)
    raw_accounts = service.management().accounts().list().execute()['items']
    accounts = [
        account.Account(raw, service, credentials) for raw in raw_accounts
    ]
    return addressable.List(accounts, indices=['id', 'name'], insensitive=True)
Пример #2
0
    def get_ga_service(self):
        service = build('analytics', 'v3', http=self.client)
        raw_accounts = service.management().accounts().list().execute(
        )['items']
        accounts = [
            account.Account(raw, service, self.client.credentials)
            for raw in raw_accounts
        ]

        self.accounts = addressable.List(accounts,
                                         indices=['id', 'name'],
                                         insensitive=True)

        return addressable.List(accounts,
                                indices=['id', 'name'],
                                insensitive=True)
Пример #3
0
def authenticate(
        client_id=None, client_secret=None,
        client_email=None, private_key=None,
        access_token=None, refresh_token=None,
        account=None, webproperty=None, profile=None,
        identity=None, prefix=None, suffix=None,
        interactive=False, save=False):
    """
    The `authenticate` function will authenticate the user with the Google Analytics API,
    using a variety of strategies: keyword arguments provided to this function, credentials
    stored in in environment variables, credentials stored in the keychain and, finally, by
    asking for missing information interactively in a command-line prompt.

    If necessary (but only if `interactive=True`) this function will also allow the user
    to authorize this Python module to access Google Analytics data on their behalf,
    using an OAuth2 token.
    """

    #Skip

    #credentials = oauth.Credentials.find(
    #    valid=True,
    #    interactive=interactive,
    #    prefix=prefix,
    #    suffix=suffix,
    #    client_id=client_id,
    #    client_secret=client_secret,
    #    client_email=client_email,
    #    private_key=private_key,
    #    access_token=access_token,
    #    refresh_token=refresh_token,
    #    identity=identity,
    #    )

    #if credentials.incomplete:
    #    if interactive:
    #        credentials = authorize(
    #            client_id=credentials.client_id,
    #            client_secret=credentials.client_secret,
    #            save=save,
    #            identity=credentials.identity,
    #            prefix=prefix,
    #            suffix=suffix,
    #            )
    #    elif credentials.type == 2:
    #        credentials = authorize(
    #            client_email=credentials.client_email,
    #            private_key=credentials.private_key,
    #            identity=credentials.identity,
    #            save=save,
    #            )
    #    else:
    #        raise KeyError("Cannot authenticate: enable interactive authorization, pass a token or use a service account.")
    
    credentials = dict()
    credentials["access_token"] = None
    credentials["client_email"] = None
    credentials["client_id"] = None
    credentials["client_secret"] = None
    credentials["identity"] = "*****@*****.**"
    credentials["private_key"] = None
    credentials["refresh_token"] = None

    #accounts = oauth.authenticate(credentials)
    
    raw_accounts = [{'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties',
       'type': 'analytics#webproperties'},
      'created': '2006-06-07T20:01:28.000Z',
      'id': 'XXXXXX',
      'kind': 'analytics#account',
      'name': 'sitename_11',
      'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
      'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
      'updated': '2019-07-02T18:00:31.573Z'},
     {'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX/webproperties',
       'type': 'analytics#webproperties'},
      'created': '2014-02-13T03:15:18.155Z',
      'id': 'XXXXXXXX',
      'kind': 'analytics#account',
      'name': 'sitename_10',
      'permissions': {'effective': []},
      'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX',
      'updated': '2016-07-14T19:41:40.634Z'},
     {'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX/webproperties',
       'type': 'analytics#webproperties'},
      'created': '2014-05-05T18:50:09.025Z',
      'id': 'XXXXXXXX',
      'kind': 'analytics#account',
      'name': 'RankSense',
      'permissions': {'effective': ['COLLABORATE',
        'EDIT',
        'MANAGE_USERS',
        'READ_AND_ANALYZE']},
      'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXX',
      'updated': '2017-02-25T17:20:39.203Z'},
     {'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXX/webproperties',
       'type': 'analytics#webproperties'},
      'created': '2017-05-05T15:40:21.336Z',
      'id': 'XXXXXXXX',
      'kind': 'analytics#account',
      'name': 'http://sitename_09/',
      'permissions': {'effective': ['COLLABORATE',
        'EDIT',
        'MANAGE_USERS',
        'READ_AND_ANALYZE']},
      'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX',
      'updated': '2017-05-05T15:40:21.336Z'}]

    from googleanalytics import account
    
    accounts = [account.Account(raw, None, credentials) for raw in raw_accounts]
    
    #return addressable.List(accounts, indices=['id', 'name'], insensitive=True)

    #scope = navigate(accounts, account=account, webproperty=webproperty, profile=profile)
    
    return accounts #scope
Пример #4
0
def authenticate(credentials):
    client = credentials.authorize()
    service = discovery.build('analytics', 'v3', http=client)
    #raw_accounts = service.management().accounts().list().execute()['items']

    raw_accounts = [{
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2006-06-07T20:01:28.000Z',
        'id': 'XXXXXX',
        'kind': 'analytics#account',
        'name': 'sitename_11',
        'permissions': {
            'effective': ['COLLABORATE', 'READ_AND_ANALYZE']
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
        'updated': '2019-07-02T18:00:31.573Z'
    }, {
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2014-02-13T03:15:18.155Z',
        'id': 'XXXXXXXX',
        'kind': 'analytics#account',
        'name': 'sitename_10',
        'permissions': {
            'effective': []
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX',
        'updated': '2016-07-14T19:41:40.634Z'
    }, {
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2014-05-05T18:50:09.025Z',
        'id': 'XXXXXXXX',
        'kind': 'analytics#account',
        'name': 'RankSense',
        'permissions': {
            'effective':
            ['COLLABORATE', 'EDIT', 'MANAGE_USERS', 'READ_AND_ANALYZE']
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXX',
        'updated': '2017-02-25T17:20:39.203Z'
    }, {
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2017-05-05T15:40:21.336Z',
        'id': 'XXXXXXXX',
        'kind': 'analytics#account',
        'name': 'http://sitename_09/',
        'permissions': {
            'effective':
            ['COLLABORATE', 'EDIT', 'MANAGE_USERS', 'READ_AND_ANALYZE']
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX',
        'updated': '2017-05-05T15:40:21.336Z'
    }]

    accounts = [
        account.Account(raw, service, credentials) for raw in raw_accounts
    ]
    return addressable.List(accounts, indices=['id', 'name'], insensitive=True)