我正在尝试将google analytics api用于我的帐户.所以首先我允许使用脱机刷新令牌访问应用程序.当我尝试刷新令牌时购买我收到"Invalid Grant"错误.尝试用php客户端库刷新并用curl手动刷新.
这是手动卷曲:
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"client_id" => 'xxxxxxxx-d28qutrse5bvaf7n4a37qgs5ieijvp9n.apps.googleusercontent.com',
"client_secret" => 'xxxxxxxxxxxxx');
$clienttoken_post["refresh_token"] = $refresh_token;
$clienttoken_post["grant_type"] = "refresh_token";
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
$authObj = json_decode($json_response);
print_r($authObj);
exit();
Run Code Online (Sandbox Code Playgroud)
我使用simple.php示例在之前的调用中获得的刷新令牌:
require_once '../../src/apiClient.php';
require_once '../../src/contrib/apiAnalyticsService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Google Analytics PHP Starter Application");
// Visit https://code.google.com/apis/console?api=analytics to generate your
// client id, client secret, and to register your …Run Code Online (Sandbox Code Playgroud) 谷歌有一个关于移动设备分析数据的例子.代码在这里提供.我添加了jar文件,所有内容编译都很好,但是运行应用程序时出错了.出于安全原因,我拿出了UA ID(不确定是否重要)
LogCat为我提供了以下信息:E/AndroidRuntime(1175):java.lang.NoClassDefFoundError:com.google.android.apps.analytics.GoogleAnalyticsTracker AND E/AndroidRuntime(1130):at com.google.android.apps.analytics. sample.TestActivity.onCreate(TestActivity.java:19)
从它的说法,它找不到googleAnalyticTracker?但是,如果它编译得好,为什么它不能找到它?
package com.google.android.apps.analytics.sample;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class TestActivity extends Activity {
GoogleAnalyticsTracker tracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tracker = GoogleAnalyticsTracker.getInstance();
// Start the tracker in manual dispatch mode...
// tracker.startNewSession("", this);
// ...alternatively, the tracker can be started with a dispatch interval
// (in seconds).
tracker.startNewSession("", 20, this);
setContentView(R.layout.main);
Button createEventButton = (Button) findViewById(R.id.NewEventButton);
createEventButton.setOnClickListener(new OnClickListener() {
@Override
public …Run Code Online (Sandbox Code Playgroud) 我正在发送用户时间数据,sendTimingWithCategory:withTimeInterval:withName:withLabel但我似乎无法在Google Analytics报告工具上找到这些数据.
在我的应用程序中,我尝试捕获不同类型的用户计时,这里有一些代码片段:
// duration1 & duration2 are instances of NSTimeInterval
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker sendTimingWithCategory:@"DurationOnApp" withValue:duration1 withName:nil withLabel:nil];
[tracker sendTimingWithCategory:@"DurationOnSectionA" withValue:duration2 withName:nil withLabel:nil];
Run Code Online (Sandbox Code Playgroud)
它让我印象深刻:是因为我应该给出一个价值,name而不是把它当作"零".
我正在开发 RoR 应用程序,它允许用户使用谷歌帐户登录并从他的分析帐户之一下载/上传报告数据。我使用omniauth-google-oauth2 gem 通过google 帐户进行授权,并使用google-api-client与Google Analytics 进行交互。问题是,当我尝试使用analytics.management.accounts.list方法获取帐户列表,并将google令牌作为授权参数之一传递时,GA会响应403权限不足错误。
我想,我必须让用户在授权过程中授予读取分析数据的权限。我怎样才能做到这一点?
我读过很多相关问题,但没有找到解决我的确切问题的方法。
这是代码:
require 'google/api_client'
client = Google::APIClient.new(:application_name => 'something you like', :application_version => '1')
client.authorization.access_token = 'HERE_GOES_TOKEN'
ga = client.discovered_api('analytics', 'v3')
client.execute(:api_method => ga.management.accounts.list)
Run Code Online (Sandbox Code Playgroud) 我正在使用Google AnalyticsAPI来制作Python程序.
目前它能够进行特定的查询,但......
是否可以获取包含Google Analytics帐户中所有数据的大型JSON?
我一直在寻找,我没有找到任何答案.
有人知道它是否可能以及如何?
我刚刚为 Laravel 下载了这个包。
它是一个 Google Anayltics 软件包,我遵循了设置帐户的所有步骤。我遇到的问题是调用方法。例如,当它说:
以下是检索当天和过去 7 天的访问者和综合浏览量数据的示例。
$analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(7));
Run Code Online (Sandbox Code Playgroud)
我尝试在我的函数中这样做:
<?php
namespace App\Http\Controllers\Admin;
use Carbon\Carbon;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Spatie\Analytics\Analytics;
use Illuminate\Support\Collection;
class DashboardController extends Controller {
public function index() {
$analytics = Analytics::fetchVisitorsAndPageViews(Period::days(7));
dd($analytics);
return view('admin.dashboard-v2');
}
}
Run Code Online (Sandbox Code Playgroud)
它给了我这样的错误:
非静态方法 Spatie\Analytics\Analytics::fetchVisitorsAndPageViews() 不应静态调用
我在这里错过了什么吗?除了 Github 自述文件之外,我在网上找不到任何特定的文档
我正在使用 google Analytics 的报告 api v4。我想在后端显示一个图表,其中显示一些指标的过去 30 天。问题是,我只得到累积/求和值。
例如,这是我发送到 api 的正文
body = {
reportRequests: [{
dateRanges: [
{
startDate: Date.parse('2016/10/01'),
endDate: Date.parse('2016/10/31')
}
],
viewId: '12345',
metrics: [{ expression: "ga:users" }],
dimensions: [{ name: "ga:pagePath" }]
}]
}
Run Code Online (Sandbox Code Playgroud)
然后我得到很多 URL(当然,我没有过滤输出),如下所示:
{"reports"=>
[{"columnHeader"=>
{"dimensions"=>["ga:pagePath"],
"metricHeader"=>
{"metricHeaderEntries"=>[{"name"=>"ga:users", "type"=>"INTEGER"}]}},
"data"=>
{"rows"=>
[{"dimensions"=>["/"], "metrics"=>[{"values"=>["2854"]}]},
{"dimensions"=>["/?extlink_img=0"], "metrics"=>[{"values"=>["113"]}]},
{"dimensions"=>["/?v=338"], "metrics"=>[{"values"=>["12"]}]},
...
Run Code Online (Sandbox Code Playgroud)
但是,当我想要最近 30 天的用户数以获取特定路线(例如)时,我应该如何查询 api /?这可能吗?
analytics google-analytics google-analytics-api universal-analytics
这是我的 Models.py
import argparse
import os
from django.db import models
from django.db import models
from django.contrib.auth.models import User
from oauth2client import tools
from oauth2client.client import flow_from_clientsecrets, Storage
CLIENT_SECRETS = os.path.join(
os.path.dirname(__file__), 'client_secrets.json')
TOKEN_FILE_NAME = 'credentials.dat'
FLOW = flow_from_clientsecrets(
CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/analytics.readonly',
message='%s is missing' % CLIENT_SECRETS
)
def prepare_credentials():
parser = argparse.ArgumentParser(parents=[tools.argparser])
flags = parser.parse_args()
# Retrieve existing credendials
storage = Storage(TOKEN_FILE_NAME)
credentials = storage.get()
# If no credentials exist, we create new ones
if credentials is None or credentials.invalid:
credentials …Run Code Online (Sandbox Code Playgroud) python django google-analytics google-analytics-api oauth-2.0
这是从 Biq Query 导出到 Google 存储的简单代码(以 CSV 格式)
def export_data():
client = bigquery.Client()
project = 'xxxxx'
dataset_id = 'xxx'
table_id = 'xxx'
bucket_name = 'xxx'
destination_uri = 'gs://{}/{}'.format(bucket_name, 'EXPORT_FILE.csv')
dataset_ref = client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
extract_job = client.extract_table(
table_ref,
destination_uri,
# Location must match that of the source table.
location='EU') # API request
extract_job.result() # Waits for job to complete.
print('Exported {}:{}.{} to {}'.format(
project, dataset_id, table_id, destination_uri))
Run Code Online (Sandbox Code Playgroud)
它非常适合通用表,但是当我尝试从保存的表 VIEW 导出数据时,它失败并出现以下错误:
BadRequest: 400 Using table xxx:xxx.xxx@123456 is not allowed …Run Code Online (Sandbox Code Playgroud) python google-analytics google-analytics-api google-bigquery