Google AnalyticsAPI包含路径

I am trying to set the include path dynamically in my code using what Google has supplied: set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');

I am still relatively noob to PHP and I am going to assume the /path/to/ needs to be changed to something else. I have tried setting it to /home/expiredf/public_html/google-api-php-client/srcBut that is not working.

Could someone please assist me to get through this HelloAnalyticsAPI.php tutorial?

Also before anyone links other questions with answers, I have looked through most of them and tried to implement their solutions but they are not working for me as they seem to be explained with a higher knowledge of PHP in mind. Basic and dumbed down answers are appreciated.

The best answer to your question is to say don't use that tutorial. That tutorial is extremely out of date and uses the old PHP-client-Lib, this has been reported to Google.

PHP client library

The newest version of the Google PHP client library can be found on Github. google-api-php-client this client lib is updated regularly whenever anything changes. You will need to copy the entire src/Google directory to the directory of your application. I don’t recommend only taking the files that you need unless you really know what you are doing.

Oauth2

There are 3 steps to Oauth2 this is why it is called 3 legged authentication. In the first step you ask the user to give you access, second step the user gives you access, third and final step you exchange the access given to you by the user for the access to the data.

<?php         
require_once 'Google/Client.php';     
require_once 'Google/Service/Analytics.php';       
session_start();      
$client = new Google_Client();
    $client->setApplicationName("Client_Library_Examples");
    $client->setDeveloperKey("{devkey}");  
    $client->setClientId('{clientid}.apps.googleusercontent.com');
    $client->setClientSecret('{clientsecret}');
    $client->setRedirectUri('http://www.daimto.com/Tutorials/PHP/Oauth2.php');
    $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));

    //For loging out.
    if ($_GET['logout'] == "1") {
    unset($_SESSION['token']);
       }   

    // Step 2: The user accepted your access now you need to exchange it.
    if (isset($_GET['code'])) {

        $client->authenticate($_GET['code']);  
        $_SESSION['token'] = $client->getAccessToken();
        $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
    }

    // Step 1:  The user has not authenticated we give them a link to login    
    if (!$client->getAccessToken() && !isset($_SESSION['token'])) {
        $authUrl = $client->createAuthUrl();
        print "<a class='login' href='$authUrl'>Connect Me!</a>";
        }        

    // Step 3: We have access we can now create our service
    if (isset($_SESSION['token'])) {
        print "<a class='logout' href='".$_SERVER['PHP_SELF']."?logout=1'>LogOut</a><br>";
        $client->setAccessToken($_SESSION['token']);
        $service = new Google_Service_Analytics($client);    

        // request user accounts
        $accounts = $service->management_accountSummaries->listManagementAccountSummaries();

       foreach ($accounts->getItems() as $item) {
        echo "Account: ",$item['name'], "  " , $item['id'], "<br /> 
";        
        foreach($item->getWebProperties() as $wp) {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WebProperty: ' ,$wp['name'], "  " , $wp['id'], "<br /> 
";    

            $views = $wp->getProfiles();
            if (!is_null($views)) {
                foreach($wp->getProfiles() as $view) {
                //  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;View: ' ,$view['name'], "  " , $view['id'], "<br /> 
";    
                }
            }
        }
    } // closes account summaries

    }
 print "<br><br><br>";
 print "Access from google: " . $_SESSION['token']; 
?>

This code is ripped directly from my tutorial: Google Oauth2 PHP - Google Analytics API the tutorial is kept up to date. If this post is old you may want to see if there have been any changes in the code.