I had successfully configured google analytics api and get successful data.
I want to access analytics api without gmail login.
i.e. I will hard code credentials to for login, but how to do it with PHP?
Is there any api function to achive this task (for PHP)
Thanks!
The Google Analytics API is not fit for what you want for several reasons.
With these things in mind if you want to show your users the data you should build some kind of system that downloads the right data you want to show offline, store it in a database and display on the page. This way you can query the data once and show multiple times and not expose your credentials.
Google even published an AppEngine Application that does just that. It queries data and store in a database so it can be viewed by any unathenticated users and with minimum latency since at the view time it's just retrieved from the datastore. It's called Google Analytics superProxy.
UPDATE 09/02
When doing the request on your application you still need to complete oAuth and as you want it to be automated you want to avoid the login screen. There are 2 options
Use Service Account: https://developers.google.com/api-client-library/php/auth/service-accounts https://developers.google.com/analytics/solutions/articles/hello-analytics-api#authorize_access
It needs google-api-php-client library, you can create a service account in your google developer console, then add the email if this account into your Google analytics profile 'User Management' for the profile that your want to access. The follow the code in the links above, you should be able to access your Google analytics data without Goolge login (because your already provide serive account email and p12 key for authorization)
Hi Kiran,
Service Account
Using server side authorization with the Google Python Client API you can use this demo to get access in google analytics data and charts for every user without login.
oAuth for Google APP
The other way is to use oAuth. But in this case you need a payable Google Apps for work Account Google Apps You can read here how to combine Apps and oAuth for access without login.
I have added here the working code for the new (2016) Google Client PHP API Beta for anonymous access using json - including an amChart.
Additionally the renewing process for the json credential files can be automated - this is not done in this code example. A ClientLogin token can last for 2 weeks from the issue date, but this limit is service-specific and can be shorter. You can change lifetime in Google_AssertionCredentials.php(24) though this is a security risk (for your money - if someone calls the site automatically you run out of the allowed duty free volume)
To make the autoload.php work correctly, you have to install the Client PHP API ressources by composer.phar into htdocs(Apache) or wwwroot(IIS) and place this code in the folder "vendor".
I did not use dataLoader and commented it out, for amChart stucks in my environment on load. Therefore I used the dataprovider, which works reliable.
Best regards Axel Arnold Bangert - Herzogenrath 2016
The Hello Analytics API: PHP Quickstart Guide for Service Accounts will walk you through the steps necessary to create and add a service account to your existing Google Analytics Account/Property/View.
Once you download have the php client libs and the p12 file downloaded from developer console you can create an authorized analytics service object as follows:
With the returned service object you can now make calls to the Google Analytics APIs: