小编Urd*_*dro的帖子

TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是'list'

我无法将函数作为参数传递给另一个函数.这是我的代码:

ga.py:

def display_pageviews(hostname):
    pageviews_results = get_pageviews_query(service, hostname).execute()
    if pageviews_results.get('rows', []):
        pv = pageviews_results.get('rows')
        return pv[0]
    else:
        return None


def get_pageviews_query(service, hostname):  
    return service.data().ga().get(
        ids=VIEW_ID,
        start_date='7daysAgo',
        end_date='today',
        metrics='ga:pageviews',
        sort='-ga:pageviews',
        filters='ga:hostname==%s' % hostname,)
Run Code Online (Sandbox Code Playgroud)

models.py:

class Stats(models.Model):
    user = models.OneToOneField('auth.User')
    views = models.IntegerField()
    visits = models.IntegerField()
    unique_visits = models.IntegerField()
Run Code Online (Sandbox Code Playgroud)

updatestats.py:

class Command(BaseCommand):

    def handle(self, *args, **options):
        users = User.objects.all()
        try:
            for user in users:
                hostname = '%s.%s' % (user.username, settings.NETWORK_DOMAIN)
                stats = Stats.objects.update_or_create(
                    user=user,
                    views=display_pageviews(hostname),
                    visits=display_visits(hostname),
                    unique_visits=display_unique_visits(hostname),)
        except FieldError:
            print ('There was …
Run Code Online (Sandbox Code Playgroud)

python django python-3.x

21
推荐指数
1
解决办法
13万
查看次数

('意外的凭证类型',无,'预期','service_account')和oauth2client(Python)

我正在尝试使用此指南获取Google Analytics数据:https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

def get_access_token(request):
    return {'access_t': ServiceAccountCredentials.from_json_keyfile_name(
        KEY_FILEPATH, SCOPE).get_access_token().access_token }
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我正在尝试创建一个函数,并将访问令牌返回到我的管理模板中的上下文.

然而.我得到这个错误我不知道该怎么办:

('Unexpected credentials type', None, 'Expected', 'service_account')
Run Code Online (Sandbox Code Playgroud)

这可能是什么问题?

python django google-analytics google-api python-3.x

8
推荐指数
1
解决办法
5034
查看次数