2016-08-05 22 views
0

Google Search Console APIにクエリを実行していて、データを取得していますが、特定の行を取得できません。Google Search Console APIのクエリPHP

$fromDate = date('Y-m-d', strtotime('-3 months')); 
$toDate = date('Y-m-d', strtotime('-1 day')); 

$client = new Google_Client(); 
$client->setAuthConfigFile(base_path().'/client_id.json'); 
$client->setAccessToken($cust->user_token); 
$client->addScope(Google_Service_Webmasters::WEBMASTERS_READONLY); 
$webmaster = new Google_Service_Webmasters($client); 
$url = $cust->console_url; 
$options = []; 

$search = new Google_Service_Webmasters_SearchAnalyticsQueryRequest; 
$search->setStartDate($fromDate); 
$search->setEndDate($toDate); 
$search->setDimensions(['date']); 
$search->setAggregationType('auto'); 

$console = $webmaster->urlcrawlerrorscounts->query($url, $options)->getCountPerTypes(); 
dd($console); 

レスポンス;

array:20 [▼ 
    0 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#301 ▼ 
    #collection_key: "entries" 
    #internal_gapi_mappings: [] 
    +category: "notFound" 
    #entriesType: "Google_Service_Webmasters_UrlCrawlErrorCount" 
    #entriesDataType: "array" 
    +platform: "web" 
    #modelData: array:1 [▼ 
     "entries" => array:1 [▼ 
     0 => array:2 [▼ 
      "count" => "64" 
      "timestamp" => "2016-08-04T20:15:25.816Z" 
     ] 
     ] 
    ] 
    #processed: [] 
    } 
    1 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#302 ▶} 
    2 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#305 ▶} 
    3 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#306 ▶} 
    4 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#307 ▶} 
    5 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#308 ▶} 
    6 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#309 ▶} 
    7 => Google_Service_Webmasters_UrlCrawlErrorCountsPerType {#310 ▶} 

私はカテゴリとプラットフォームを得ることができますが、あなたの応答は、 その場合はJSONに似ている

+0

ねえ、私はこれを見て、私はしようとしていますGoogleSearchConsoleに接続してください... 私はあなたのやり方を "コピー"しようとしましたが、どこからこのアクセストークンを取得しましたか? $ client-> setAccessToken($ cust-> user_token); あなたからの回答を得るにはとてもいいですね:) – trunco

答えて

0

Iゲストをカウント#modelData>エントリ> 0>内のカウントにアクセスする方法を考え出すことはできませんあなた$ responds_decode = json_decode( "string json"、true)を試すことができます 次に、配列のようなオブジェクトにアクセスします。このクラスが持つ

$response = $webmaster->urlcrawlerrorscounts 
     ->query($url, $options) 
     ->getCountPerTypes(); 

foreach ($response->getCountPerTypes() as $type) { 

    $entries = []; 

    foreach ($type->getEntries() as $entry) { 
     $count = $entry->getCount(); 
     $timestamp = $entry->getTimestamp(); 
     $entries[] = [$count, $timestamp]; 
    } 

    $platform = $type->getPlatform(); 
    $category = $type->getCategory(); 

    // Do what you want with it ... 
} 

ザッツすべてのメソッド::

関連する問題