title: error: Undefined property while fetching data from Google analytics
body: <p>I'm facing problems fetching data (Profile list to be specific) from <code>google analytics</code>. The credentials like <code>client_id</code>, secret etc are in place and it does allow user to login successfully, but I'm stuck in the next step where I need to fetch the list of profiles (list of websites). I did go through the official docs as per <a href="https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/list" rel="nofollow"> Google Views (Profiles): list</a> but while I try it, I get an error:</p>
  
  <p><code>Undefined property: App\Http\Controllers\UserController::$analytics</code></p>
  
  <p>the detailed error:</p>
  
  <p><code>in UserController.php line 84
  at HandleExceptions-&gt;handleError('8', 'Undefined property: App\Http\Controllers\UserController::$analytics', 'C:\xampp\htdocs\Laravel Projects\testApp\app\Http\Controllers\UserController.php', '84', array('request' =&gt; object(Request), 'google_redirect_url' =&gt; 'http://localhost:8000/glogin', 'gClient' =&gt; object(Google_Client), 'google_oauthV2' =&gt; object(Google_Service_Oauth2), 'guser' =&gt; null, 'user' =&gt; object(User), 'token' =&gt; array('access_token' =&gt; 'TOKEN GOES HERE', 'token_type' =&gt; 'Bearer', 'expires_in' =&gt; '3600', 'id_token' =&gt; 'ID_TOKEN GOES HERE', 'created' =&gt; 'CREATED DATA GOES HERE'))) in UserController.php line 84</code></p>
  
  <p>I do understand there's an error when I try to fetch the data, but then I don't really understand as to how should i be doing that. Anyone has any idea? Please help!</p>
  
  <p>here's the <code>Controller</code></p>
  
  <pre><code> class UserController extends Controller
  {
    public function googleLogin(Request $request)  {
      $google_redirect_url = route('glogin');
      $gClient = new \Google_Client();
      $gClient-&gt;setApplicationName(config('services.google.app_name'));
      $gClient-&gt;setClientId(config('services.google.client_id'));
      $gClient-&gt;setClientSecret(config('services.google.client_secret'));
      $gClient-&gt;setRedirectUri($google_redirect_url);
      $gClient-&gt;setDeveloperKey(config('services.google.api_key'));
  
      $gClient-&gt;addScope(\Google_Service_Analytics::ANALYTICS_READONLY);
      $gClient-&gt;addScope("email");
      $gClient-&gt;addScope("profile");
      $gClient-&gt;setAccessType("offline");
      $google_oauthV2 = new \Google_Service_Oauth2($gClient);
      if ($request-&gt;get('code')){
          $gClient-&gt;authenticate($request-&gt;get('code'));
          $request-&gt;session()-&gt;put('token', $gClient-&gt;getAccessToken());
      }
      if ($request-&gt;session()-&gt;get('token'))
      {
          $gClient-&gt;setAccessToken($request-&gt;session()-&gt;get('token'));
      }
      if ($gClient-&gt;getAccessToken())
      {
          //For logged in user, get details from google using access token
          $guser = $google_oauthV2-&gt;userinfo-&gt;get();
  
          $request-&gt;session()-&gt;put('name', $guser['name']);
          if ($user =User::where('email',$guser['email'])-&gt;first())
          {
  
  
          }else{
              //register your user with response data
  
              return User::create([
                  'name' =&gt; $guser-&gt;name,
                  'email' =&gt; $guser-&gt;email,
              ]);
          }
  
          //LINE NO 84 is below:
          $profiles = $this-&gt;analytics-&gt;management_profiles
              -&gt;listManagementProfiles();
          $accounts = $accountsObject-&gt;getItems();
  
          return $accounts;
          //return redirect()-&gt;route('user.glist');
      } else
      {
          //For Guest user, get google login url
       }
     }
  }
  </code></pre>