Pregunta

I am building a web application using Google Analytics API, but I am running into some difficulties thinking of an implementation.

I am allowing the user to select their profile from three drop-down menus that are dependent on each other (think country->state->city). I am using AJAX to grab a value from the first drop-down (country), and I am trying to populate the second drop-down from Google Analytics API in an external PHP script.

I am trying to bring the Analytics object ($analytics) over to an external script via a $_SESSION variable from index.php, but I cannot call the $analytics functions I need to populate the second drop-down.

I var_dumped the variable, it initially told me it's an incomplete PHP class, so I serialized it and deserialized between the two classes. However, it still gives me:

Fatal error:  Call to a member function listManagementWebproperties() on a non-object

I am wondering if there is a way to do this?

Just to clarify:

In index.php

        //create a session analytics object for use in external scripts
        $_SESSION['analytics'] = serialize($analytics;) //used for API calls

and the line in an external script throwing the error in my AJAX request, propertyID.php:

$analytics = unserialize($_SESSION['analytics']);
$webProperty = $analytics->management_webproperties->listManagementWebproperties($accountID); //the array used to populate the drop-down

EDIT: Could this be an issue due to the API object?

¿Fue útil?

Solución 2

I found a solution/workaround to my problem.

Instead of storing the Google_Service_Analytics() object in the session, you can store the Google_Client() object in the session instead. From there you can declare the $analytics object as you would normally:

$analytics = new Google_Service_Analytics($client);

Otros consejos

I suppose it could be related to some transient data that makes the class not serializable.

I think you have to create the Google objects in every page call and serialize in $_SESSION only the data useful to create these instances.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top