• Hola, soy nuevo en el foro y me uni por que estoy buscando ayuda con un plugin que quiero dasarrollar.

    El plugin es para wordpress, y lo que busca es poder integrar herramientas de analitica web, bueno he tenido un problema con usar la API de google analytics. pondre a continuacion el codigo.

    require_once (plugin_dir_path( __FILE__ )."/google/google-api-php-client/src/Google_Client.php");
    require_once (plugin_dir_path( __FILE__ )."/google/google-api-php-client/src/contrib/Google_PlusService.php");
    require_once (plugin_dir_path( __FILE__ )."/google/google-api-php-client/src/contrib/Google_AnalyticsService.php");
    //include (plugin_dir_path( __FILE__ )."/facebook/libreria.php");
    
    session_start();
    
    $client = new Google_Client();
    $client->setApplicationName('Hello Analytics API Sample');
    
    $client->setClientId('//aqui va el id');
    $client->setClientSecret('// aqui el secret');
    $client->setRedirectUri('// uri');
    $client->setDeveloperKey('// key');
    $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
    
    $client->setUseObjects(true);
    
    if (isset($_GET['code'])) {
      $client->authenticate();
      $_SESSION['token'] = $client->getAccessToken();
      $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
      header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
    }
    
    if (isset($_SESSION['token'])) {
      $client->setAccessToken($_SESSION['token']);
    }
    
    if (!$client->getAccessToken()) {
      $authUrl = $client->createAuthUrl();
      print "<a class='login' href='$authUrl'>Connect Me!</a>";
    
    } else {
    
    $analytics = new Google_AnalyticsService($client);
    runMainDemo($analytics);
    
    }
    
    function runMainDemo(&$analytics) {
      try {
    
        // Step 2. Get the user's first view (profile) ID.
        $profileId = getFirstProfileId($analytics);
    
        if (isset($profileId)) {
    
          // Step 3. Query the Core Reporting API.
          $results = getResults($analytics, $profileId);
          $results2= getResultsPages($analytics, $profileId);
    
          // Step 4. Output the results.
          printResults($results);
          echo getPagesRows($results);
        }
    
      } catch (apiServiceException $e) {
        // Error from the API.
        print 'There was an API error : ' . $e->getCode() . ' : ' . $e->getMessage();
    
      } catch (Exception $e) {
        print 'There wan a general error : ' . $e->getMessage();
      }
    }

    y el problema o error que me esta tirando es el siguiente.

    Fatal error: Uncaught exception ‘Google_Exception’ with message ‘Cant add services after having authenticated’ in /home/hermanas/public_html/wp-content/plugins/ilogica_plugin/google/google-api-php-client/src/Google_Client.php:115 Stack trace: #0 /home/hermanas/public_html/wp-content/plugins/ilogica_plugin/google/google-api-php-client/src/contrib/Google_AnalyticsService.php(1227): Google_Client->addService(‘analytics’, ‘v3’) #1 /home/hermanas/public_html/wp-content/plugins/ilogica_plugin/panel.php(49): Google_AnalyticsService->__construct(Object(Google_Client)) #2 /home/hermanas/public_html/wp-content/plugins/ilogica_plugin/ilogica_plugin.php(44): require_once(‘/home/hermanas/…’) #3 [internal function]: ilogica_plugin_panel_menu(») #4 /home/hermanas/public_html/wp-includes/plugin.php(429): call_user_func_array(‘ilogica_plugin_…’, Array) #5 /home/hermanas/public_html/wp-admin/admin.php(217): do_action(‘toplevel_page_i…’) #6 {main} thrown in /home/hermanas/public_html/wp-content/plugins/ilogica_plugin/google/google-api-php-client/src/Google_Client.php on line 115

    Mi problema es que el mismo código lo he probado fuera de wordpress, pero al ponerlo en un plugin dentro de wordpress, me ha tirado ese error que no he hayado como sacarmelo. ojala me puedan ayudar serian de mucha ayuda de verdad, de ante mano muchas gracias.

Viendo 1 respuesta (de un total de 1)
Viendo 1 respuesta (de un total de 1)
  • El debate ‘Problema Plugin y API GOOGLE’ está cerrado a nuevas respuestas.