我在试着获得个人资料列表https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/list
以下是web版本的示例:
Request
GET https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles?key={YOUR_API_KEY}
Authorization: Bearer
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
- Hide headers -
Cache-Control: private, max-age=0, must-revalidate, no-transform
Content-Encoding: gzip
Content-Type: application/json; charset=UTF-8
Date: Tue, 09 Sep 2014 16:20:18 GMT
Etag: "oq4YecK1DDgQfhLS-HzmxjZUB9I/ooSCrThtdvH0a3h5ysvIA31TDu0"
Expires: Tue, 09 Sep 2014 16:20:18 GMT
Server: GSE
Transfer-Encoding: Identity
{
"kind": "analytics#profiles",
"username": "admin@domain.com",
"totalResults": 38,
"startIndex": 1,
"itemsPerPage": 1000,
"items": [
...
]
}下面是我使用https://github.com/google/google-api-ruby-client/ gem的红宝石代码示例。
def self.ga_client
client = Google::APIClient.new(
application_name: configatron.google_analytics.application_name,
application_version: configatron.google_analytics.application_version
)
key_file = File.join(configatron.google_analytics.pk12_file_path)
key = Google::APIClient::PKCS12.load_key(key_file, 'notasecret')
service_account = Google::APIClient::JWTAsserter.new(
configatron.google_analytics.service_email,
configatron.google_analytics.scope,
key
)
client.authorization = service_account.authorize
client
end
client = self.ga_client
analytics = client.discovered_api('analytics', configatron.google_analytics.version)
result = client.execute(
api_method: analytics.management.profiles.list,
parameters: {
accountId: "~all",
webPropertyId: "~all"
}
)
Response
#<Google::APIClient::Result:0x00000108c71a10 @request=#<Google::APIClient::Request:0x00000108cc3f90 @parameters={"accountId"=>"~all", "webPropertyId"=>"~all"}, @headers={"User-Agent"=>"DLM/1.0 google-api-ruby-client/0.7.1 Mac OS X/10.9.3\n (gzip)", "Accept-Encoding"=>"gzip", "Content-Type"=>""}, @api_method=#<Google::APIClient::Method:0x8474c6b8 ID:analytics.management.profiles.list>, @authenticated=nil, @authorization=#<Signet::OAuth2::Client:0x000001013435a8 @token_credential_uri=#<Addressable::URI:0x809a19e4 URI:https://accounts.google.com/o/oauth2/token>, @expiry=60, @extension_parameters={}, @additional_parameters={}, @scope=["https://www.googleapis.com/auth/analytics.readonly", "https://www.googleapis.com/auth/prediction"], @issuer="filtered@developer.gserviceaccount.com", @principal=nil, @audience="https://accounts.google.com/o/oauth2/token", @signing_key=#<OpenSSL::PKey::RSA:0x00000101341000>, @grant_type=nil, @refresh_token=nil, @code=nil, @issued_at=2014-09-09 20:19:07 +0400, @expires_in=3600, @access_token="ya29.ewBSHe0Wh5oGeKoe8aJtdpzVb-Nhr9SF0O39mdE1HgF3zTKs-8wBHL5M">, @body="">, @response=#<Faraday::Response:0x00000108c798c8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body="{\"kind\":\"analytics#profiles\",\"username\":\"filtered@developer.gserviceaccount.com\",\"totalResults\":25,\"startIndex\":1,\"itemsPerPage\":1000,\"items\":...从控制台上看只有25张唱片,为什么?我试着玩最大物品选项,但没有运气,有什么提示吗?
发布于 2014-09-19 07:30:46
Google为您提供选项参数。
因此,我不认为更改最大值(最大值-结果)的值会有帮助,因为你只有35条记录。使用google,我们使用的是不同的帐户(xyz@gmail.com)&对于我们使用的API (XXX@developer.gserviceaccount.com)
我尝试使用上面的选项使用谷歌客户端,它给我显示了正确的结果。
我是怎么做的?
我相信你一定遵循了以下步骤。请再过一次确认。
- Select the Service account option and press Create client ID
- Download private key
- Copy the Service Account Email address i.e. `XXXX@@developer.gserviceaccount.com`
- Visit your [GA Admin](https://www.google.com/analytics/web/#management/Accounts/) and add this email as a user to your properties
- This is a must; you'll get cryptic errors otherwise.
bundle exec ruby test.rb执行代码结论:可能错过了对某些属性/帐户的许可,用于开发人员的电子邮件。请用XXX@developer.gserviceaccount.com交叉验证实际的GA帐户(xyz@gmail.com)配置文件列表
https://stackoverflow.com/questions/25847859
复制相似问题