{"id":1030,"date":"2011-07-26T02:18:24","date_gmt":"2011-07-25T17:18:24","guid":{"rendered":"http:\/\/codaholic.org\/?p=1030"},"modified":"2011-07-26T02:23:25","modified_gmt":"2011-07-25T17:23:25","slug":"phpgoogle-data-export-api%e3%82%92%e5%88%a9%e7%94%a8%e3%81%97%e3%81%a6%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e3%81%ab%e9%a0%bc%e3%82%89%e3%81%9a%e3%81%abgoogle-analytics%e3%81%8b%e3%82%89","status":"publish","type":"post","link":"https:\/\/codaholic.org\/?p=1030","title":{"rendered":"[PHP]\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u983c\u3089\u305a\u306bGoogle Data Export API\u3092\u5229\u7528\u3057\u3066Google Analytics\u304b\u3089\u30da\u30fc\u30b8\u30d3\u30e5\u30fc\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>Google Analytics\u306b\u306fAPI\u304c\u7528\u610f\u3055\u308c\u3066\u304a\u308a\u3001\u5916\u90e8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Google Data Export API\u3068\u3044\u3046API\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u8a8d\u8a3c\u304b\u3089\u30c7\u30fc\u30bf\u53d6\u5f97\u307e\u3067\u306e\u624b\u9806\u3092\u7c21\u7565\u5316\u3059\u308b\u305f\u3081\u306b\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3044\u304f\u3064\u304b\u5b58\u5728\u3057\u307e\u3059\u3002\u3067\u3059\u304c\u3053\u306e\u8a18\u4e8b\u3067\u306f\u305d\u308c\u3089\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u305b\u305a\u306b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u516c\u958b\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><br \/>\n\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u6307\u5b9a\u3057\u305f\u671f\u9593\u306e\u30b5\u30a4\u30c8\u5168\u4f53\u306e\u30da\u30fc\u30b8\u30d3\u30e5\u30fc\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u30da\u30fc\u30b8\u30d3\u30e5\u30fc\u6570\u3060\u3051\u304c\u307d\u3064\u308a\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>[php]<br \/>\n<?php\n\t#\u8a8d\u8a3c\n\t$data = array(\n\t\t'accountType' => &#8216;GOOGLE&#8217;,<br \/>\n\t\t&#8216;Email&#8217; => &#8216;info@example.com&#8217;,<br \/>\n\t\t&#8216;Passwd&#8217; => &#8216;yourpassword&#8217;,<br \/>\n\t\t&#8216;service&#8217; => &#8216;analytics&#8217;,<br \/>\n\t\t&#8216;source&#8217; => &#8216;Sample&#8217;<br \/>\n\t);<\/p>\n<p>\t$options = array(<br \/>\n\t\t&#8216;http&#8217; => array(<br \/>\n\t\t\t&#8216;method&#8217; => &#8216;POST&#8217;,<br \/>\n\t\t\t&#8216;content&#8217; => http_build_query($data)<br \/>\n\t\t)<br \/>\n\t);<\/p>\n<p>\t$response = @file_get_contents(&#8216;https:\/\/www.google.com\/accounts\/ClientLogin&#8217;, false, stream_context_create($options));<br \/>\n\t$auth = explode(&#8220;\\n&#8221;, $response);<\/p>\n<p>\t#\u30c7\u30fc\u30bf\u53d6\u5f97<br \/>\n\t$header = array(<br \/>\n\t\t&#8216;Authorization: GoogleLogin auth=&#8217;. substr($auth[2], 5,1024)<br \/>\n\t);<\/p>\n<p>\t$options = array(<br \/>\n\t\t&#8216;http&#8217; => array(<br \/>\n\t\t\t&#8216;method&#8217; => &#8216;GET&#8217;,<br \/>\n\t\t\t&#8216;header&#8217; => $header<br \/>\n\t\t)<br \/>\n\t);<\/p>\n<p>\t$response = @file_get_contents(&#8216;https:\/\/www.google.com\/analytics\/feeds\/data?ids=ga:47745665&#038;metrics=ga:pageviews&#038;start-date=2011-07-25&#038;end-date=2011-07-25&#038;v=2&#8217;, false, stream_context_create($options));<br \/>\n\t$xml = simplexml_load_string($response);<br \/>\n\tprint $xml->entry->children(&#8216;dxp&#8217;, true)->metric->attributes()->value;<br \/>\n?><br \/>\n[\/php]<\/p>\n<p>\u5927\u304d\u304f\u5206\u3051\u30662\u3064\u306e\u90e8\u5206\u306b\u5206\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u8a8d\u8a3c\u3068\u30c7\u30fc\u30bf\u53d6\u5f97\u3067\u3059\u3002<\/p>\n<div class=\"subtitle\">1.\u3000\u8a8d\u8a3c<\/div>\n<p>Google Analytics\u304b\u3089\u30c7\u30fc\u30bf\u3092\u5f97\u308b\u305f\u3081\u306b\u306f\u307e\u305a\u8a8d\u8a3c\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30c7\u30fc\u30bf\u3092\u898b\u308b\u8cc7\u683c\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u306e\u30c1\u30a7\u30c3\u30af\u3067\u3059\u306d\u3002\u300chttps:\/\/www.google.com\/accounts\/ClientLogin\u300d\u306b\u5bfe\u3057\u3066Google Analytics\u306eID\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u30bb\u30c3\u30c8\u3057\u3066\u3001POST\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3092\u884c\u3044\u307e\u3059\u3002\u3053\u306e\u30b3\u30fc\u30c9\u3092\u6d41\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u3054\u81ea\u5206\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u3082\u306e\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002\u305d\u3046\u3059\u308b\u3068\u8a8d\u8a3c\u30ad\u30fc\u306e\u3088\u3046\u306a\u9577\u3044\u6587\u5b57\u5217\u304c\u6539\u884c\u533a\u5207\u308a\u3067\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002\u305d\u306e\u4e2d\u306e\u300cAuth=\u300d\u306b\u7d9a\u304f\u30ad\u30fc\u3092\u53d6\u308a\u51fa\u3057\u3066\u5909\u6570\u306b\u4fdd\u5b58\u3057\u3066\u304a\u304d\u307e\u3059\u3002Auth\u306e\u4ed6\u306b\u30822\u3064\u306e\u30ad\u30fc\u304c\u8fd4\u3055\u308c\u307e\u3059\u304c\u3001\u30da\u30fc\u30b8\u30d3\u30e5\u30fc\u3092\u53d6\u5f97\u3059\u308b\u6bb5\u968e\u3067\u306f\u4f7f\u308f\u306a\u304f\u3066\u3082\u826f\u3044\u3088\u3046\u3067\u3059\u3002<br \/>\n<br\/ ><\/p>\n<div class=\"subtitle\">2.\u3000\u30c7\u30fc\u30bf\u53d6\u5f97<\/div>\n<p>\u5148\u307b\u3069\u4fdd\u5b58\u3057\u305f\u3001Auth\u306e\u30ad\u30fc\u3092\u30d8\u30c3\u30c0\u30fc\u306b\u30bb\u30c3\u30c8\u3057\u3066\u300chttps:\/\/www.google.com\/analytics\/feeds\/data\u300d\u306b\u5bfe\u3057\u3066GET\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002\u3069\u3093\u306a\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u3044\u306e\u304b\u306b\u3088\u3063\u3066GET\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5909\u66f4\u3057\u3066\u4e0b\u3055\u3044\u3002\u3053\u3053\u3067\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3000ids=ga:47745665\u3000\u2192\u3000Google Analytics\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30ebID\u3067\u3059\u3002<br \/>\n\u3000metrics=ga:pageviews\u3000\u2192\u3000\u53d6\u5f97\u3057\u305f\u3044\u30c7\u30fc\u30bf\u306e\u7a2e\u985e\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u30da\u30fc\u30b8\u30d3\u30e5\u30fc\u304c\u6b32\u3057\u3044\u5834\u5408\u306f\u3053\u3046\u3057\u307e\u3059\u3002<br \/>\n\u3000start-date=2011-07-25\u3000\u2192\u3000\u30c7\u30fc\u30bf\u53d6\u5f97\u7bc4\u56f2\u306e\u958b\u59cb\u65e5\u3067\u3059\u3002<br \/>\n\u3000end-date=2011-07-25\u3000\u2192\u3000\u30c7\u30fc\u30bf\u53d6\u5f97\u7bc4\u56f2\u306e\u7d42\u4e86\u65e5\u30021\u65e5\u5206\u3060\u3051\u306a\u306e\u3067\u958b\u59cb\u65e5\u3068\u540c\u3058\u65e5\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3000v=2\u3000\u2192\u3000\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u6307\u5b9a\u3067\u3059\u3002\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b2\u3092\u6307\u5b9a\u3059\u308b\u3088\u3046\u306b\u66f8\u3044\u3066\u3042\u3063\u305f\u6c17\u304c\u3057\u307e\u3059\u306e\u3067\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u306f\u3082\u3063\u3068\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u8a73\u3057\u3044\u4ed5\u69d8\u306f<a href=\"http:\/\/code.google.com\/intl\/ja\/apis\/analytics\/docs\/gdata\/gdataReferenceDimensionsMetrics.html\" target=\"_blank\">Google\u306e\u300c\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u3068\u6307\u6a19\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u300d<\/a>\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p>XML\u3067\u7d50\u679c\u304c\u8fd4\u5374\u3055\u308c\u307e\u3059\u306e\u3067\u304a\u306a\u3058\u307f\u306esimplexml_load_string\u3067\u30d1\u30fc\u30b9\u3092\u3057\u3066\u300c$xml->entry->children(&#8216;dxp&#8217;, true)->metric->attributes()->value\u300d\u3068\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u30da\u30fc\u30b8\u30d3\u30e5\u30fc\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google Analytics\u306b\u306fAPI\u304c\u7528\u610f\u3055\u308c\u3066\u304a\u308a\u3001\u5916\u90e8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Google Data Export API\u3068\u3044\u3046API\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u8a8d\u8a3c\u304b\u3089\u30c7\u30fc\u30bf\u53d6\u5f97\u307e\u3067\u306e\u624b\u9806\u3092\u7c21\u7565\u5316\u3059\u308b\u305f\u3081 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[39,143,4],"tags":[272,173,244],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8gd1W-gC","_links":{"self":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1030"}],"collection":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1030"}],"version-history":[{"count":9,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1030\/revisions"}],"predecessor-version":[{"id":1039,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1030\/revisions\/1039"}],"wp:attachment":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}