NikosTsolakos / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

I am trying to list all the accounts created by user and also profiles underneath them. #89

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
I am trying to list all the accounts created by user(authentication is done). I 
have used the code provided on net: 

require_once(ABSPATH.'/google-api-php-client/src/apiClient.php');
require_once(ABSPATH.'/google-api-php-client/src/contrib/apiPlusService.php');
require_once(ABSPATH.'/google-api-php-client/src/contrib/apiAnalyticsService.php
');

$client = new apiClient();
$client->setApplicationName("Google+ PHP Starter Application");
// Visit https://code.google.com/apis/console?aredirect uri.
// $client->setClientId('insert_your_oauth2_pi=plus to generate your
// client id, client secret, and to register your client_id');
$client->setClientId(''); //insert_your_oauth2_client_id
$client->setClientSecret(''); //insert_your_oauth2_client_secret
$client->setRedirectUri(''); //insert_your_oauth2_redirect_uri
$client->setDeveloperKey(''); //insert_your_simple_api_key
$service = new apiAnalyticsService($client); /*...............object of class 
'apiAnalyticsService' used to get analytical data...............*/

if (isset($_GET['logout'])) {
          unset($_SESSION['token']);
        }

if (isset($_GET['code'])) {
        $client->authenticate();
        $_SESSION['code'] = $_GET['code'];
        $_SESSION['token'] = $client->getAccessToken();
        $redirect = 'http://' . $_SERVER['HTTP_HOST'] . '/members/'.$current_user->user_login.'/domains';
        //header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
} 
if(isset($_REQUEST['error'])) {
        $_SESSION['prevState'] = $_REQUEST['state'];
         bp_core_add_message('You have denied to give access to Domainz.se !','error');
        $redirect = 'http://' . $_SERVER['HTTP_HOST'] . '/members/'.$current_user->user_login.'/domains';
        header("Location: ".$redirect); // filter_var($redirect, FILTER_SANITIZE_URL));
    }

if (isset($_SESSION['token'])) { 
      $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
$props = 
$service->management_webproperties->listManagementWebproperties("~all");
print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";

$accounts = $service->management_accounts->listManagementAccounts();
            print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";

$segments = $service->management_segments->listManagementSegments();
             print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";

$goals = $service->management_goals->listManagementGoals("~all", "~all", 
"~all");
            print "<h1>Segments</h1><pre>" . print_r($goals, true) . "</pre>";

$_SESSION['token'] = $client->getAccessToken();
} 

But it is not displaying anything. :-( .. Please help and point where I am 
doing wrong. The gmail account through which I logged-in is an analytical 
account and having 3 accounts(domains).

Original issue reported on code.google.com by test123....@gmail.com on 28 Feb 2012 at 7:56

GoogleCodeExporter commented 8 years ago
It is giving me this error: 

Fatal error: Uncaught exception 'apiServiceException' with message 'Error 
calling GET 
https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties?k
ey=AIzaSyDXb3pEfUyhMOtnBT8bEfD_HghmbjtyJfY: (401) Invalid Credentials' in 
/home/domainz-www/devi.domainz.se/public/google-api-php-client/src/io/apiREST.ph
p:86 Stack trace: #0 
/home/domainz-www/devi.domainz.se/public/google-api-php-client/src/io/apiREST.ph
p(56): apiREST::decodeHttpResponse(Object(apiHttpRequest)) #1 
/home/domainz-www/devi.domainz.se/public/google-api-php-client/src/service/apiSe
rviceResource.php(186): apiREST::execute(Object(apiServiceRequest)) #2 
/home/domainz-www/devi.domainz.se/public/google-api-php-client/src/contrib/apiAn
alyticsService.php(61): apiServiceResource->__call('list', Array) #3 
/home/domainz-www/devi.domainz.se/public/wp-content/themes/bp-domainz/auth-page.
php(54): 
ManagementWebpropertiesServiceResource->listManagementWebproperties('~all') #4 
/home/domainz-www/devi.domainz.se/public/wp-includes/template-loader.php(43): 
include( in 
/home/domainz-www/devi.domainz.se/public/google-api-php-client/src/io/apiREST.ph
p on line 86 

Please draw some light where I am doing things in wrong way. Thanks

Original comment by test123....@gmail.com on 28 Feb 2012 at 8:32

GoogleCodeExporter commented 8 years ago
I have the same problem but i have no solution .

Original comment by blastmed...@gmail.com on 24 May 2012 at 12:10

GoogleCodeExporter commented 8 years ago
I'm afraid that 'apiAnalyticsService' is now 'Google_AnalyticsService'.

Try replacing:

$service = new apiAnalyticsService($client);

with

$service = new Google_AnalyticsService($client);

Original comment by meann...@gmail.com on 23 Feb 2013 at 5:18

GoogleCodeExporter commented 8 years ago
Thanks Meannate!

Original comment by ianbar...@google.com on 22 Mar 2013 at 1:52